CommonJS hybrid module with exports.import
configured still treated as CommonJS with module:ES2020 and moduleResolution:Node16
#50083
Labels
Milestone
Bug Report
π Search Terms
π Version & Regression Information
4.7.4, 4.8.0-dev.20220728
β― Playground Link
The playground doesn't seem to allow me to configure
module: es2020
andmoduleResolution: node16
so here's a repo with the smallest repro I could come up with instead:https://github.com/valeriangalliat/typescript-exports-bug-repro
π» Code
Main project:
node_modules/foo
dependency:π Actual behavior
During build, the following error occurs:
π Expected behavior
Builds successfully.
It appears that despite following the types in
exports['.'].import.types
, TypeScript still interprets the types as being CommonJS because thepackage.json
of the dependency doesn't set"type": "module"
.For example the above examples has TypeScript build when doing
foo.default.bar()
, but it doesn't result in runnable code.Essentially it looks like TypeScript supports hybrid dependencies that default to ESM and declare
exports['.'].require
, but doesn't support hybrid dependencies that default to CJS and declareexports['.'].import
.The text was updated successfully, but these errors were encountered: