Title: Incorrect resolution of CJS types from dual-package dependency in multi-project build with mixed `ESNext/Bundler` and `NodeNext` modules · Issue #57553 · microsoft/TypeScript · GitHub
Open Graph Title: Incorrect resolution of CJS types from dual-package dependency in multi-project build with mixed `ESNext/Bundler` and `NodeNext` modules · Issue #57553 · microsoft/TypeScript
X Title: Incorrect resolution of CJS types from dual-package dependency in multi-project build with mixed `ESNext/Bundler` and `NodeNext` modules · Issue #57553 · microsoft/TypeScript
Description: 🔎 Search Terms "NodeNext", "ESNext", "Bundler", "module", "moduleResolution", "ESM", "CJS", "multi-project", "dual package" 🕗 Version & Regression Information This is the behavior in every version I tried (5.0.4, 5.1.6, 5.2.2, 5.3.3, and...
Open Graph Description: 🔎 Search Terms "NodeNext", "ESNext", "Bundler", "module", "moduleResolution", "ESM", "CJS", "multi-project", "dual package" 🕗 Version & Regression Information This is the behavior in every version ...
X Description: 🔎 Search Terms "NodeNext", "ESNext", "Bundler", "module", "moduleResolution", "ESM", "CJS", "multi-project", "du...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/57553
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect resolution of CJS types from dual-package dependency in multi-project build with mixed `ESNext/Bundler` and `NodeNext` modules","articleBody":"### 🔎 Search Terms\n\n\"NodeNext\", \"ESNext\", \"Bundler\", \"module\", \"moduleResolution\", \"ESM\", \"CJS\", \"multi-project\", \"dual package\"\n\n### 🕗 Version \u0026 Regression Information\n\n- This is the behavior in every version I tried (5.0.4, 5.1.6, 5.2.2, 5.3.3, and 5.5.0-dev.20240226), and I reviewed the FAQ for entries about ESM\r\n\n\n### ⏯ Playground Link\n\nhttps://github.com/haines/typescript-dual-package-esnext-bundler-nodenext\n\n### 💻 Code\n\nIt's probably less confusing to look at the repo, sorry 🙈 I've tried to make it as minimal as possible.\r\n\r\nThis bug occurs in a multi-project build where one project (`app`) is configured to use `ESNext` module and `Bundler` module resolution, and another (`lib`) is using `NodeNext`. Everything is set up to use ESM with `\"type\": \"module\"` in package.json.\r\n\r\nIf both projects depend on the same dual-packaged dependency (`dep`), then when `app` imports `dep` directly, TypeScript correctly resolves the ESM types. However, transitive imports of `dep` through `lib` are resolved to the CJS types.\n\n### 🙁 Actual behavior\n\nTypeScript 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.\n\n### 🙂 Expected behavior\n\nTypeScript resolves the ESM types for all imports of the dual-packaged dependency.\n\n### Additional information about the issue\n\nOriginally encountered in `@bufbuild/protobuf`: https://github.com/bufbuild/protobuf-es/issues/718\r\n\r\nOur `app` is full-stack and built with Vite, which is why we want to use `ESNext/Bundler`, but our `lib` is consumed by other Node.js-only projects that are built with tsc and therefore it makes sense for that to be built with `NodeNext`.","author":{"url":"https://github.com/haines","@type":"Person","name":"haines"},"datePublished":"2024-02-26T21:39:42.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/57553/TypeScript/issues/57553"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d084781b-f261-ee9a-56a5-858f117dc2a3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DB0C:1846A4:57A77AA:74CA848:6A5DCE7A |
| html-safe-nonce | 39c36464e576997968dacd929d521d081f3db3ea573b970f5c4fc49607e46378 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjBDOjE4NDZBNDo1N0E3N0FBOjc0Q0E4NDg6NkE1RENFN0EiLCJ2aXNpdG9yX2lkIjoiNTYzMTQxODAwNzY5NDQ2MjU4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dd0ad775efbe2cd02d5df13f83e39abad1f37ab49634f1b7ef9e47c9f2d84fc2 |
| hovercard-subject-tag | issue:2155203876 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/57553/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d8b7ad2d281dc6f2d59c42f1020905f404c331a1064821067b8b6b1677d714f6/microsoft/TypeScript/issues/57553 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d8b7ad2d281dc6f2d59c42f1020905f404c331a1064821067b8b6b1677d714f6/microsoft/TypeScript/issues/57553 |
| og:image:alt | 🔎 Search Terms "NodeNext", "ESNext", "Bundler", "module", "moduleResolution", "ESM", "CJS", "multi-project", "dual package" 🕗 Version & Regression Information This is the behavior in every version ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | haines |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width