Title: `moduleResolution: bundler` diverges from bundlers following node semantics in regards to `default` import · Issue #54102 · microsoft/TypeScript · GitHub
Open Graph Title: `moduleResolution: bundler` diverges from bundlers following node semantics in regards to `default` import · Issue #54102 · microsoft/TypeScript
X Title: `moduleResolution: bundler` diverges from bundlers following node semantics in regards to `default` import · Issue #54102 · microsoft/TypeScript
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 Repr...
Open Graph 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 moduleRe...
X 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 modu...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/54102
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`moduleResolution: bundler` diverges from bundlers following node semantics in regards to `default` import","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\nmoduleResolution bundler node webpack default namespace\r\n\r\n### 🕗 Version \u0026 Regression Information\r\n\r\n- This is the behavior in every version I tried: 5.0.4 (the only one with `moduleResolution: bundler`\r\n\r\n### ⏯ Playground Link\r\n\r\nRepro case can be found [here](https://github.com/Andarist/import-reexporting-cjs-bundlers/commit/c41f9256cf3153107226664456f667672fcd64ae)\r\n\r\n### 🙁 Actual behavior\r\n\r\nWhen resolving a `.d.mts` file that proxies to `.d.ts` in a CJS package with `moduleResolution: bundler`, TypeScript complains with an error like:\r\n\u003e `Property 'default' does not exist on type 'string'.ts(2339)`\r\n\r\nThe 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\".\r\n\r\nSo 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.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI'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.\r\n\r\ncc @andrewbranch \r\n\r\n","author":{"url":"https://github.com/Andarist","@type":"Person","name":"Andarist"},"datePublished":"2023-05-02T18:13:57.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/54102/TypeScript/issues/54102"}
| 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:50d26c75-e8b1-7572-cc7f-aa955cdf4c94 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC1A:1DF241:67096F1:891048D:6A5DE43E |
| html-safe-nonce | bbc8093bfca6e932d881a5b0fd1b180e07b0506c42d4cc77614bb6787d4afb7c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzFBOjFERjI0MTo2NzA5NkYxOjg5MTA0OEQ6NkE1REU0M0UiLCJ2aXNpdG9yX2lkIjoiMzM0OTU5NzU2NjYxMTA4ODQ0NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a0c3ee44ee0f39d80761de31c665b5fa0ca97288c01feb6f2f4a692e9081cb7d |
| hovercard-subject-tag | issue:1692880716 |
| 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/54102/issue_layout |
| twitter:image | https://opengraph.githubassets.com/99f42cdb63619f314bcae1e4966f2d9e4d61a47b3751f109eaa5badc1f5f12a8/microsoft/TypeScript/issues/54102 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/99f42cdb63619f314bcae1e4966f2d9e4d61a47b3751f109eaa5badc1f5f12a8/microsoft/TypeScript/issues/54102 |
| og:image:alt | 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 moduleRe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Andarist |
| hostname | github.com |
| expected-hostname | github.com |
| None | f068985268f2a1e272fe40dd37a3352a16d337d57ec570e56da6c2346e179f59 |
| 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 | e36408244bcd0ded36f1cfba5db8e97f99c2117e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width