You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a Node.js javascript project, it's clear what type: 'module' does, as all the Javascript files will either be cjs style with 'require' or mjs style with 'import.'
In a typescript project - and my understanding gets weaker here - that field doesn't really affect how programmers write typescript. The tsconfig.json will include a setting like module: esnext that affects the .ts code, and whatever TS compiler is used, like tsc, will consult that value to read in the ts and consult package.json type to output to the correct cjs or mjs.
For a next project, build is more complicated, as any given .ts code can run in several environments: build-time, request-time, server or client. So next owns all its own compilation with its own compiler built on swc.
Which raises the question, why would a programmer of a next project ever touch the type field?
I see various issues related to it, like some users apparently set it to module and break their build, but I'm missing the conceptual 'why'. To me this just looks like fiddling with a nextjs build internal and it would affect the code in a haphazard way at best (forex it shouldn't affect the client bundle at all).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
type: 'module'
does, as all the Javascript files will either be cjs style with 'require' or mjs style with 'import.'tsconfig.json
will include a setting likemodule: esnext
that affects the .ts code, and whatever TS compiler is used, liketsc
, will consult that value to read in the ts and consultpackage.json type
to output to the correct cjs or mjs.type
field?I see various issues related to it, like some users apparently set it to
module
and break their build, but I'm missing the conceptual 'why'. To me this just looks like fiddling with a nextjs build internal and it would affect the code in a haphazard way at best (forex it shouldn't affect the client bundle at all).Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions