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

ESM import/export is broken with Typescript >= 4.7 and moduleResolution=node16 #52

Open
GabrielDelepine opened this issue Oct 21, 2022 · 0 comments

Comments

@GabrielDelepine
Copy link

GabrielDelepine commented Oct 21, 2022

Minimal reproduction repo

https://github.com/GabrielDelepine/tsc-esm-issue-with-use-ssr

Bug report

I am migrating a repository to standard ESM, and I got the following issue with use-ssr.

 error TS2349: This expression is not callable.
  Type 'typeof import("_THE_PATH_OF_MY_PROJECT_HERE/node_modules/use-ssr/dist/useSSR")' has no call signatures.

21   const { isServer } = useSSR();

A full description of the issue, as well as a solution to fix it, is available here

From what I understood: use-ssr describes the default export from the main field of package.json, which is making Typescript interpret it as a CommonJS default export. Full explanation here

For those who are looking for an immediate solution, please find a workaround here

Environment

Node 18
Typescript 4.8.4 with the following config

{
  "compilerOptions": {
    "target": "es2017",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "baseUrl": ".",
    "paths": {
      "*": ["./app/*"],
    },
    "skipLibCheck": true,
    "strict": true,
    "strictNullChecks": true,
    "alwaysStrict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": false,
    "esModuleInterop": true,
    "module": "NodeNext",
    "moduleResolution": "node16",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "react"
  },
  "exclude": [
    "node_modules",
    "build"
  ],
  "include": [
    "**/*.ts",
    "**/*.tsx",
    "**/*.json"
  ]
}
@GabrielDelepine GabrielDelepine changed the title ESM import/export is broken with Typescript >= 4.7 and module=node16|nodenext ESM import/export is broken with Typescript >= 4.7 and moduleResolution=node16 Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant