-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
TypeScript types fail with ESM (type: module) + TSConfig module: node16 #46676
Comments
I'm guessing that since Next.js is CommonJS, the types of these exports on all next.js/packages/next/link.d.ts Lines 1 to 3 in ed51bd8
I guess the correct type would actually use the unusual TypeScript syntax https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64137/files Also added this to the issue description above. |
Indeed, adding this change here fixed the problem: import Link from './dist/client/link'
export * from './dist/client/link'
-export default Link
+export = Link @lfades @timneutkens would you accept a PR for this for all If you're skeptical of this syntax (I was too at first), there are a bunch of PRs (including this one linked in the description) that I have done recently where @andrewbranch has confirmed that this is correct and will not cause problems for other TypeScript configurations. |
I'm facing this issue as well here. To work around this temporarily, I'm building my project with ignoreBuildErrors option. Are The Types Wrong shows that the Related bugs: |
Closing as duplicate of #46078 |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #22 SMP Tue Jan 10 18:39:00 UTC 2023 Binaries: Node: 16.17.0 npm: 8.15.0 Yarn: 1.22.19 pnpm: 7.1.0 Relevant packages: next: 13.2.4-canary.0 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0
Which area(s) of Next.js are affected? (leave empty if unsure)
TypeScript support
Link to the code that reproduces this issue
https://codesandbox.io/p/sandbox/floral-thunder-44jpww?file=%2Fpages%2Findex.tsx
To Reproduce
dynamic()
functionImage
componentThis occurs with all import paths with slashes into
next
eg:next/dynamic
next/image
next/link
next/navigation
next/script
Describe the Bug
The TypeScript types for the imports at the paths mentioned above fail when using:
"type": "module"
inpackage.json
)"module": "node16"
, which was seemingly implemented by @loettz in Add support for tsconfig 'nodenext' | 'node16' #44177The code however still runs, so it seems to be a problem with the Next.js types and ESM <> CommonJS interop.
I'm guessing that since Next.js is CommonJS, the types of these exports on all
*.d.ts
files are actually wrong:next.js/packages/next/link.d.ts
Lines 1 to 3 in ed51bd8
I guess the correct type would actually use the unusual TypeScript syntax
export =
, like my PR over here:https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64137/files
cc @andrewbranch @fluggo @cseas @lfades
Workaround
A workaround is to type the import as the
.default
property, as @kachkaev shows in this discussion comment:Expected Behavior
The import should work out of the box and no TypeScript errors should appear.
See also
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: