Title: TypeScript cannot emit valid ES modules due to file extension issue · Issue #42151 · microsoft/TypeScript · GitHub
Open Graph Title: TypeScript cannot emit valid ES modules due to file extension issue · Issue #42151 · microsoft/TypeScript
X Title: TypeScript cannot emit valid ES modules due to file extension issue · Issue #42151 · microsoft/TypeScript
Description: Bug Report This report is based on the problem covered in #28288 and #16577, but intends to emphasize the fact that this explicitly precludes TS from emitting valid ECMAScript modules. Issue Because TS imports do not allow file extension...
Open Graph Description: Bug Report This report is based on the problem covered in #28288 and #16577, but intends to emphasize the fact that this explicitly precludes TS from emitting valid ECMAScript modules. Issue Becaus...
X Description: Bug Report This report is based on the problem covered in #28288 and #16577, but intends to emphasize the fact that this explicitly precludes TS from emitting valid ECMAScript modules. Issue Becaus...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/42151
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeScript cannot emit valid ES modules due to file extension issue","articleBody":"# Bug Report\r\nThis report is based on the problem covered in #28288 and #16577, but intends to emphasize the fact that this explicitly precludes TS from emitting valid ECMAScript modules.\r\n\r\n## Issue\r\nBecause TS imports do not allow file extensions, but imports in emitted ES modules are _not_ resolved to their relevant file extensions (`import ... from './myModule'` vs. `import ... from './myModule.js'`), this output is unusable unless transpiled *again* with Rollup + Babel or a similar toolkit, no matter how much active care is taken while authoring source code. Executing emitted modules will always throw `ERR_MODULE_NOT_FOUND` because these sources are not rewritten.\r\n\r\nSwitching to `\"module\": \"commonjs\"` is not a valid suggestion in this case, as the goal is to get valid ESM output.\r\n\r\n### ⏯ Playground Link\r\n\r\n\u003c!--\r\n A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n The TypeScript Workbench can be used for more complex setups, try\r\n https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n-->\r\nUse `yarn test`: https://repl.it/@christiantjl/TSImportFileExtensions\r\n\r\n\r\n### 💻 Code\r\n\r\n#### `tsconfig.json`\r\n```json\r\n{\r\n \"compilerOptions\": {\r\n \"outDir\": \"build/\",\r\n \r\n \"target\": \"esnext\",\r\n \"module\": \"esnext\",\r\n\r\n \"moduleResolution\": \"node\",\r\n \"esModuleInterop\": true\r\n }\r\n}\r\n```\r\n\r\n#### `index.ts`\r\n```typescript\r\nimport { test } from './importMe';\r\nconsole.log(test); \r\n```\r\n\r\n#### `build/index.js`\r\n```javascript\r\nimport { test } from './importMe';\r\nconsole.log(test);\r\n```\r\n\r\n### 🙁 Actual behavior\r\nThe `import { test } from './importMe'` statement is not modified.\r\n\r\n### 🙂 Expected behavior\r\n`build/index.js` should contain:\r\n```javascript\r\nimport { test } from './importMe.js';\r\nconsole.log(test);\r\n```\r\n\r\n\r\n","author":{"url":"https://github.com/ctjlewis","@type":"Person","name":"ctjlewis"},"datePublished":"2020-12-30T00:30:14Z","url":"https://github.com/microsoft/TypeScript/issues/42151"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:38f0dc03-ce56-ae34-158c-87665b3f8998 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE0C:21BD98:4CF6EC:613795:6B010C22 |
| html-safe-nonce | 5f5e0aa29ebcb475b6fa3418f9f5d329511b3136eac12dd452710177e80044cd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTBDOjIxQkQ5ODo0Q0Y2RUM6NjEzNzk1OjZCMDEwQzIyIiwidmlzaXRvcl9pZCI6IjkwNTkyNjczODU1ODM3OTkzMzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0e5817edbd4c68eeb4dfb7a66ab46edaaf67cacca45618a4cd37eac295a49336 |
| hovercard-subject-tag | issue:776143967 |
| 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/42151/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4a16006a4616fc7331ab25af0e7643f7ab1a7cd8b4f8ff2714f8dcb188bfe9ab/microsoft/TypeScript/issues/42151 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4a16006a4616fc7331ab25af0e7643f7ab1a7cd8b4f8ff2714f8dcb188bfe9ab/microsoft/TypeScript/issues/42151 |
| og:image:alt | Bug Report This report is based on the problem covered in #28288 and #16577, but intends to emphasize the fact that this explicitly precludes TS from emitting valid ECMAScript modules. Issue Becaus... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ctjlewis |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width