Description
Bug Report
π Search Terms
moduleResolution bundler node webpack default namespace
π Version & Regression Information
- This is the behavior in every version I tried: 5.0.4 (the only one with
moduleResolution: bundler
β― Playground Link
Repro case can be found here
π Actual behavior
When resolving a .d.mts
file that proxies to .d.ts
in a CJS package with moduleResolution: bundler
, TypeScript complains with an error like:
Property 'default' does not exist on type 'string'.ts(2339)
The reason that it complains about it is that TypeScript is resolving default
import as if the .d.ts
in this CJS package could export the "real" default export. webpack actually follows semantics coined by node and it loads the namespace object as the default
export of that "cjs file".
So the type-level reality diverges there from runtime. At runtime, with webpack - it works exactly like it would work in node. TypeScript thinks that the intention was to load module.exports.default
there though.
π Expected behavior
I'm not exactly sure what's the expected behavior here because "resolving" like a bundler is quite under-specified and bundlers are not quite consistent when it comes to this. Even when we check this very same repro, we can see that I had to use defaultIsModuleExports: true
in Rollup for it to behave the same. By default, Rollup behaves in the same way as TypeScript does.