-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Module resolution: default import does not work with type: module
#57743
Comments
See #50058 (comment) |
I don't fully understand that comment. Next does a default export and I do a default import. It seems simple enough that this should work? Why is the |
The comment explains all of this |
It doesn't address why TypeScript considers |
If you write your exports in ESM syntax, but the package itself is CJS (which it is), then Node16 module mode says to respect what the package says, because that's what Node does. |
For the record: |
@RyanCavanaugh I think that's a mistake. The exports are eventually transformed into ESM imports according to Node.js. Per Node.js, that transformation uses static analysis and its outcome is unknown beforehand. Accepting what the types say lets those who do know - the library authors - inform TypeScript of the final shape of the library. |
What you're describing - that package authors tell TS how their package works - is what's happening, it just happens that next is telling TS the wrong thing. |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Demo Repo
https://github.com/mohd-akram/ts-next-repro
Which of the following problems are you reporting?
The module specifier resolves at runtime, but not at build time
Demonstrate the defect described above with a code sample.
Run
tsc --showConfig
and paste its output hereRun
tsc --traceResolution
and paste its output hereToo long to paste.
Paste the
package.json
of the importing module, if it existsPaste the
package.json
of the target module, if it existsAny other comments can go here
Next types:
next/head.d.ts:
next/dist/shared/lib/head.d.ts:
The text was updated successfully, but these errors were encountered: