Title: `"module": "node16"` should support extension rewriting · Issue #49083 · microsoft/TypeScript · GitHub
Open Graph Title: `"module": "node16"` should support extension rewriting · Issue #49083 · microsoft/TypeScript
X Title: `"module": "node16"` should support extension rewriting · Issue #49083 · microsoft/TypeScript
Description: Bug Report TypeScript 4.7 RC introduces the "module": "node16" setting. When used, this requires users to use the .js extension in import paths. I strongly believe this to be a mistake and TypeScript should instead allow users to use the...
Open Graph Description: Bug Report TypeScript 4.7 RC introduces the "module": "node16" setting. When used, this requires users to use the .js extension in import paths. I strongly believe this to be a mistake and TypeScri...
X Description: Bug Report TypeScript 4.7 RC introduces the "module": "node16" setting. When used, this requires users to use the .js extension in import paths. I strongly believe this to be a ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/49083
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`\"module\": \"node16\"` should support extension rewriting","articleBody":"# Bug Report\r\n\r\nTypeScript 4.7 RC introduces the `\"module\": \"node16\"` setting. When used, this requires users to use the `.js` extension in import paths. I strongly believe this to be a mistake and TypeScript should instead allow users to use the `.ts`/`.tsx` extension of the *source* file. It would then be the TS compiler’s responsibility to rewrite this to the *output* file as necessary.\r\n\r\nI have several reasons for requesting this change:\r\n\r\n- The file with the `.js` extension most likely does not exist on disk. It *may* exist on disk if a build has been created and the output is placed right alongside the sources (not a common configuration), but otherwise the file is simply not there or in a different place than one might expect. This is confusing to users, because they need to manually consider how output files are created.\r\n- Using the `.js` extension makes the source code less portable for full-stack projects. If a user wants to use the same sources for a frontend project that uses a bundler, they will be out of luck. A bundler would be able to understand a reference to the `.ts` file (because that one actually exists on disk!), but would struggle with references to files that do not exist for its configuration.\r\n- Using the `.js` extension makes the source incompatible with Deno projects, as they use the `.ts`/`.tsx` extensions, because those are the ones that actually exist.\r\n- Using the `.js` extension is inconsistent with type import. Does `import type { MyType } from “./myFile.js”` even work? It would not make sense because the JS file contains no types. But if it doesn’t work, does that mean I still have to use the `.ts` extensions only for the types? That would be highly annoying.\r\n\r\n### 🔎 Search Terms\r\n\r\nextension rewriting esm module\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nTypeScript 4.7. RC1\r\n\r\n- I was unable to test this on prior versions because the feature is new to version 4.7.\r\n\r\n### 🙁 Actual behavior\r\n\r\nI am forced to write `import { myFunction, type MyType } from “./myFile.js”` despite “./myFile.js” not being a valid path in my project.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI should be able to write `import { myFunction, type MyType } from “./myFile.ts”` because “./myFile.ts” is the actual file I am referring to. Upon compilation I would expect TypeScript to rewrite the path so the output works correctly too.","author":{"url":"https://github.com/arendjr","@type":"Person","name":"arendjr"},"datePublished":"2022-05-12T14:34:16Z","url":"https://github.com/microsoft/TypeScript/issues/49083"}
| 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:a9689f42-4a6f-2ba7-cb40-fab813fb6a74 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 842A:29FFA9:AD8B5C:DD6AF7:6B00F52D |
| html-safe-nonce | e7eb7af8459c453e51e9db15e1abfff159369f4c37ae88d94a64b39160238680 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDJBOjI5RkZBOTpBRDhCNUM6REQ2QUY3OjZCMDBGNTJEIiwidmlzaXRvcl9pZCI6IjU2MDk0MzU4MDI0NDM1MTEwODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d7dd6490ef22aab89c31fe21578ae3076a0b006d7489cab22a577856c3976206 |
| hovercard-subject-tag | issue:1234080106 |
| 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/49083/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d4cc5dc09cb6a5870913296a3bbeef5efd3323f27841588a7468bc944bb0e733/microsoft/TypeScript/issues/49083 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d4cc5dc09cb6a5870913296a3bbeef5efd3323f27841588a7468bc944bb0e733/microsoft/TypeScript/issues/49083 |
| og:image:alt | Bug Report TypeScript 4.7 RC introduces the "module": "node16" setting. When used, this requires users to use the .js extension in import paths. I strongly believe this to be a mistake and TypeScri... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | arendjr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width