Incorrect resolution of CJS types from dual-package dependency in multi-project build with mixed ESNext/Bundler
and NodeNext
modules
#57553
Labels
Milestone
🔎 Search Terms
"NodeNext", "ESNext", "Bundler", "module", "moduleResolution", "ESM", "CJS", "multi-project", "dual package"
🕗 Version & Regression Information
⏯ Playground Link
https://github.com/haines/typescript-dual-package-esnext-bundler-nodenext
💻 Code
It's probably less confusing to look at the repo, sorry 🙈 I've tried to make it as minimal as possible.
This bug occurs in a multi-project build where one project (
app
) is configured to useESNext
module andBundler
module resolution, and another (lib
) is usingNodeNext
. Everything is set up to use ESM with"type": "module"
in package.json.If both projects depend on the same dual-packaged dependency (
dep
), then whenapp
importsdep
directly, TypeScript correctly resolves the ESM types. However, transitive imports ofdep
throughlib
are resolved to the CJS types.🙁 Actual behavior
TypeScript resolves the CJS types for transitive imports of the dual-packaged dependency. If the CJS types are not perfectly compatible with the ESM types, then this causes compile errors.
🙂 Expected behavior
TypeScript resolves the ESM types for all imports of the dual-packaged dependency.
Additional information about the issue
Originally encountered in
@bufbuild/protobuf
: bufbuild/protobuf-es#718Our
app
is full-stack and built with Vite, which is why we want to useESNext/Bundler
, but ourlib
is consumed by other Node.js-only projects that are built with tsc and therefore it makes sense for that to be built withNodeNext
.The text was updated successfully, but these errors were encountered: