Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowSyntheticDefaultImports not working with ESNext module #60107

Closed
bosens-China opened this issue Sep 30, 2024 · 3 comments
Closed

allowSyntheticDefaultImports not working with ESNext module #60107

bosens-China opened this issue Sep 30, 2024 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@bosens-China
Copy link

πŸ”Ž Search Terms

allowSyntheticDefaultImports
lodash-es

πŸ•— Version & Regression Information

Version 4. x does not support 'moduleSolution': 'Bundler', so I only tried 5.6.2

⏯ Playground Link

https://github.com/bosens-China/picture-bed

πŸ’» Code

import _ from 'lodash-es';

// Usage of lodash function
console.log(_.debounce(() => console.log('Hello, world!'), 1000));
  • tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "skipLibCheck": true,
    "resolveJsonModule": true,
    /* Bundler mode */
    "moduleResolution": "Bundler",
    "allowImportingTsExtensions": true,
    "isolatedModules": true,
    "moduleDetection": "force",
    "noEmit": true,
    "jsx": "react-jsx",

    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true
  },
  "include": ["src"]
}

πŸ™ Actual behavior

src/store/features/users/slice.ts:3:8 - error TS1192: Module '"E:/picture-bed/node_modules/.pnpm/@types[email protected]/node_modules/@types/lodash-es/index"' has no default export.

πŸ™‚ Expected behavior

I expected to be able to use the syntax import _ from 'lodash-es'; without errors, as allowSyntheticDefaultImports should allow default imports for modules that do not have a default export.

Additional information about the issue

No response

@RyanCavanaugh
Copy link
Member

allowSyntheticDefaultImports should allow default imports for modules that do not have a default export.

This is only true when importing from a CJS module, but lodash-es obviously isn't one. ESM-to-ESM behavior is not affected

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Sep 30, 2024
@bosens-China
Copy link
Author

bosens-China commented Sep 30, 2024

@RyanCavanaugh
This will make me very confused, I am using vscode development, but ts is not reporting errors in the editor, nor is it using the build tool. It only appears when tsc checks, is there any option that can be controlled? I want this to be unified

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants