tsconfig / bases

Hosts TSConfigs to extend in a TypeScript app, tuned to a particular runtime environment
MIT License
6.4k stars 240 forks source link

node presets: consider adding allowSyntheticDefaultImports: false? #251

Open domdomegg opened 9 months ago

domdomegg commented 9 months ago

My understanding of allowSyntheticDefaultImports is that it assumes you have an extra build step that converts imports of the form import React from "react"; to import * as React from "react"; (so you can write the former in place of the latter).

However, by default Node does not do this natively. This can cause runtime errors when importing packages that haven't reexported everything as a default.

Also see:

I'm not fully confident about this - would be keen for others to weigh in whether this assessment is accurate.

zanminkian commented 8 months ago

https://github.com/microsoft/TypeScript/issues/54500#issuecomment-1574042512

TS core team will deprecate this flag later. This flag should set to true. So this issue can be closed I think 🤔️

alexanderchr commented 4 days ago

Node does add default exports when consuming commonjs modules from es modules, see

https://nodejs.org/api/esm.html#commonjs-namespaces

To support this, when importing CommonJS from an ECMAScript module, a namespace wrapper for the CommonJS module is constructed, which always provides a default export key pointing to the CommonJS module.exports value.