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
{{ message }}
Repository navigation
Consult package.json contents when creating tsconfig.json under tsc --init to determine better defaultsΒ #51207
> npx tsc --init
Created a new tsconfig.json with:
TS
target: es2016
module: commonjs
strict: true
esModuleInterop: true
skipLibCheck: true
forceConsistentCasingInFileNames: true
You can learn more at https://aka.ms/tsconfig
π Expected behavior
it should check the package.json to determine that module should be nodenext or something
changed the title [-]`tsc --init` sets `module` to `"commonjs"` when `type` is `"module"` in `package.json`[/-][+]Consult `package.json` contents when creating `tsconfig.json` under `tsc --init` to determine better defaults[/+]on Oct 18, 2022
moduleResolution should also default to nodenext or node16 when "type": "module" is in package.json.
also, maybe it would be better to not even include these options when running tsc --init and instead just infer the default values from package.json when they are not present in tsconfig.json
I would argue that module+moduleResolution should be set to nodenext+nodenext/node16+node16 for both CommonJS and ES Module projects, not only for the latter.
After all, node16+node16 are the settings that allows you to correctly transpile dynamic import().
The current default of commonjs+node does not let you use ESM packages inside a CommonJS project, even if a dynamic import was used, it fails quietly (#45125).
Activity
[-]`tsc --init` sets `module` to `"commonjs"` when `type` is `"module"` in `package.json`[/-][+]Consult `package.json` contents when creating `tsconfig.json` under `tsc --init` to determine better defaults[/+]DetachHead commentedon Apr 14, 2023
moduleResolutionshould also default tonodenextornode16when"type": "module"is inpackage.json.also, maybe it would be better to not even include these options when running
tsc --initand instead just infer the default values frompackage.jsonwhen they are not present intsconfig.jsonakwodkiewicz commentedon Nov 22, 2023
I would argue that
module+moduleResolutionshould be set tonodenext+nodenext/node16+node16for both CommonJS and ES Module projects, not only for the latter.After all,
node16+node16are the settings that allows you to correctly transpile dynamicimport().The current default of
commonjs+nodedoes not let you use ESM packages inside a CommonJS project, even if a dynamic import was used, it fails quietly (#45125).