Title: Module resolution: ESM-style namespace importing is broken · Issue #58817 · microsoft/TypeScript · GitHub
Open Graph Title: Module resolution: ESM-style namespace importing is broken · Issue #58817 · microsoft/TypeScript
X Title: Module resolution: ESM-style namespace importing is broken · Issue #58817 · microsoft/TypeScript
Description: Demo Repo https://github.com/kungfooman/ts_esm_fail Which of the following problems are you reporting? Something else more complicated which I'll explain in more detail Demonstrate the defect described above with a code sample. import * ...
Open Graph Description: Demo Repo https://github.com/kungfooman/ts_esm_fail Which of the following problems are you reporting? Something else more complicated which I'll explain in more detail Demonstrate the defect descr...
X Description: Demo Repo https://github.com/kungfooman/ts_esm_fail Which of the following problems are you reporting? Something else more complicated which I'll explain in more detail Demonstrate the defect d...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/58817
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Module resolution: ESM-style namespace importing is broken","articleBody":"### Demo Repo\r\n\r\nhttps://github.com/kungfooman/ts_esm_fail\r\n\r\n### Which of the following problems are you reporting?\r\n\r\nSomething else more complicated which I'll explain in more detail\r\n\r\n### Demonstrate the defect described above with a code sample.\r\n\r\n```ts\r\nimport * as ts from 'typescript';\r\n// What could possibly go wrong... besides everything.\r\nconsole.log(\"ts.ScriptTarget.Latest\", ts.ScriptTarget.Latest);\r\n```\r\n\r\n### Run `tsc --showConfig` and paste its output here\r\n\r\n```\r\n> error TS5081: Cannot find a tsconfig.json file at the current directory: /var/www/html/ts_esm_fail.\r\n```\r\n\r\nI have a `jsconfig.json`, fix your tool. But `tsc -p jsconfig.json` prints nothing (no errors).\r\n\r\n### Run `tsc --traceResolution` and paste its output here\r\n\r\n```\r\nVersion 4.9.3\r\ntsc: The TypeScript Compiler - Version 4.9.3 \r\n TS \r\nCOMMON COMMANDS\r\n\r\n tsc\r\n Compiles the current project (tsconfig.json in the working directory.)\r\n\r\n tsc app.ts util.ts\r\n Ignoring tsconfig.json, compiles the specified files with default compiler options.\r\n\r\n tsc -b\r\n Build a composite project in the working directory.\r\n\r\n tsc --init\r\n Creates a tsconfig.json with the recommended settings in the working directory.\r\n\r\n tsc -p ./path/to/tsconfig.json\r\n Compiles the TypeScript project located at the specified path.\r\n\r\n tsc --help --all\r\n An expanded version of this information, showing all possible compiler options\r\n\r\n tsc --noEmit\r\n tsc --target esnext\r\n Compiles the current project, with additional settings.\r\n\r\nCOMMAND LINE FLAGS\r\n\r\n --help, -h Print this message.\r\n\r\n --watch, -w Watch input files.\r\n\r\n --all Show all compiler options.\r\n\r\n --version, -v Print the compiler's version.\r\n\r\n --init Initializes a TypeScript project and creates a tsconfig.json file.\r\n\r\n --project, -p Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.\r\n\r\n --build, -b Build one or more projects and their dependencies, if out of date\r\n\r\n --showConfig Print the final configuration instead of building.\r\n\r\nCOMMON COMPILER OPTIONS\r\n\r\n --pretty Enable color and formatting in TypeScript's output to make compiler errors easier to read.\r\n type: boolean\r\n default: true\r\n\r\n --target, -t Set the JavaScript language version for emitted JavaScript and include compatible library declarations.\r\n one of: es3, es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext\r\n default: es3\r\n\r\n --module, -m Specify what module code is generated.\r\n one of: none, commonjs, amd, umd, system, es6/es2015, es2020, es2022, esnext, node16, nodenext\r\n default: undefined\r\n\r\n --lib Specify a set of bundled library declaration files that describe the target runtime environment.\r\n one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, esnext, dom, dom.iterable, webworker, webworker.importscripts, webworker.iterabl e, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol. wellknown, es2016.array.include, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asyncitera ble/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, e s2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.prom ise/esnext.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array/esnext.array, es2022.error, es2022.intl, es2022.object, es2022.sh aredmemory, es2022.string/esnext.string, esnext.intl\r\n default: undefined\r\n\r\n --allowJs Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files.\r\n type: boolean\r\n default: false\r\n\r\n --checkJs Enable error reporting in type-checked JavaScript files.\r\n type: boolean\r\n default: false\r\n\r\n --jsx Specify what JSX code is generated.\r\n one of: preserve, react, react-native, react-jsx, react-jsxdev\r\n default: undefined\r\n\r\n --declaration, -d Generate .d.ts files from TypeScript and JavaScript files in your project.\r\n type: boolean\r\n default: `false`, unless `composite` is set\r\n\r\n --declarationMap Create sourcemaps for d.ts files.\r\n type: boolean\r\n default: false\r\n\r\n --emitDeclarationOnly Only output d.ts files and not JavaScript files.\r\n type: boolean\r\n default: false\r\n\r\n --sourceMap Create source map files for emitted JavaScript files.\r\n type: boolean\r\n default: false\r\n\r\n --outFile Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output.\r\n\r\n --outDir Specify an output folder for all emitted files.\r\n\r\n --removeComments Disable emitting comments.\r\n type: boolean\r\n default: false\r\n\r\n --noEmit Disable emitting files from a compilation.\r\n type: boolean\r\n default: false\r\n\r\n --strict Enable all strict type-checking options.\r\n type: boolean\r\n default: false\r\n\r\n --types Specify type package names to be included without being referenced in a source file.\r\n\r\n --esModuleInterop Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility.\r\n type: boolean\r\n default: false\r\n\r\nYou can learn about all of the compiler options at https://aka.ms/tsc\r\n```\r\n\r\n### Paste the `package.json` of the *importing* module, if it exists\r\n\r\n```json\r\n{\r\n \"name\": \"ts_esm_fail\",\r\n \"version\": \"1.0.0\",\r\n \"description\": \"\",\r\n \"main\": \"index.js\",\r\n \"type\": \"module\",\r\n \"scripts\": {\r\n \"start\": \"node src/index.js\"\r\n },\r\n \"author\": \"\",\r\n \"license\": \"ISC\",\r\n \"dependencies\": {\r\n \"typescript\": \"^5.4.5\"\r\n }\r\n}\r\n```\r\n\r\n### Paste the `package.json` of the *target* module, if it exists\r\n\r\n```json\r\n{\r\n \"name\": \"typescript\",\r\n \"author\": \"Microsoft Corp.\",\r\n \"homepage\": \"https://www.typescriptlang.org/\",\r\n \"version\": \"5.4.5\",\r\n \"license\": \"Apache-2.0\",\r\n \"description\": \"TypeScript is a language for application scale JavaScript development\",\r\n \"keywords\": [\r\n \"TypeScript\",\r\n \"Microsoft\",\r\n \"compiler\",\r\n \"language\",\r\n \"javascript\"\r\n ],\r\n \"bugs\": {\r\n \"url\": \"https://github.com/Microsoft/TypeScript/issues\"\r\n },\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/Microsoft/TypeScript.git\"\r\n },\r\n \"main\": \"./lib/typescript.js\",\r\n \"typings\": \"./lib/typescript.d.ts\",\r\n \"bin\": {\r\n \"tsc\": \"./bin/tsc\",\r\n \"tsserver\": \"./bin/tsserver\"\r\n },\r\n \"engines\": {\r\n \"node\": \">=14.17\"\r\n },\r\n \"files\": [\r\n \"bin\",\r\n \"lib\",\r\n \"!lib/enu\",\r\n \"LICENSE.txt\",\r\n \"README.md\",\r\n \"SECURITY.md\",\r\n \"ThirdPartyNoticeText.txt\",\r\n \"!**/.gitattributes\"\r\n ],\r\n \"devDependencies\": {\r\n \"@esfx/canceltoken\": \"^1.0.0\",\r\n \"@octokit/rest\": \"^20.0.2\",\r\n \"@types/chai\": \"^4.3.11\",\r\n \"@types/glob\": \"^8.1.0\",\r\n \"@types/microsoft__typescript-etw\": \"^0.1.3\",\r\n \"@types/minimist\": \"^1.2.5\",\r\n \"@types/mocha\": \"^10.0.6\",\r\n \"@types/ms\": \"^0.7.34\",\r\n \"@types/node\": \"latest\",\r\n \"@types/source-map-support\": \"^0.5.10\",\r\n \"@types/which\": \"^3.0.3\",\r\n \"@typescript-eslint/eslint-plugin\": \"^6.19.0\",\r\n \"@typescript-eslint/parser\": \"^6.19.0\",\r\n \"@typescript-eslint/utils\": \"^6.19.0\",\r\n \"azure-devops-node-api\": \"^12.3.0\",\r\n \"c8\": \"^9.1.0\",\r\n \"chai\": \"^4.4.1\",\r\n \"chalk\": \"^4.1.2\",\r\n \"chokidar\": \"^3.5.3\",\r\n \"diff\": \"^5.1.0\",\r\n \"dprint\": \"^0.45.0\",\r\n \"esbuild\": \"^0.20.0\",\r\n \"eslint\": \"^8.56.0\",\r\n \"eslint-formatter-autolinkable-stylish\": \"^1.3.0\",\r\n \"eslint-plugin-local\": \"^3.1.0\",\r\n \"eslint-plugin-no-null\": \"^1.0.2\",\r\n \"eslint-plugin-simple-import-sort\": \"^10.0.0\",\r\n \"fast-xml-parser\": \"^4.3.3\",\r\n \"glob\": \"^10.3.10\",\r\n \"hereby\": \"^1.8.9\",\r\n \"jsonc-parser\": \"^3.2.0\",\r\n \"minimist\": \"^1.2.8\",\r\n \"mocha\": \"^10.2.0\",\r\n \"mocha-fivemat-progress-reporter\": \"^0.1.0\",\r\n \"ms\": \"^2.1.3\",\r\n \"node-fetch\": \"^3.3.2\",\r\n \"playwright\": \"^1.41.0\",\r\n \"source-map-support\": \"^0.5.21\",\r\n \"tslib\": \"^2.6.2\",\r\n \"typescript\": \"5.4.0-dev.20240119\",\r\n \"which\": \"^3.0.1\"\r\n },\r\n \"overrides\": {\r\n \"typescript@*\": \"$typescript\"\r\n },\r\n \"scripts\": {\r\n \"test\": \"hereby runtests-parallel --light=false\",\r\n \"test:eslint-rules\": \"hereby run-eslint-rules-tests\",\r\n \"build\": \"npm run build:compiler && npm run build:tests\",\r\n \"build:compiler\": \"hereby local\",\r\n \"build:tests\": \"hereby tests\",\r\n \"build:tests:notypecheck\": \"hereby tests --no-typecheck\",\r\n \"clean\": \"hereby clean\",\r\n \"gulp\": \"hereby\",\r\n \"lint\": \"hereby lint\",\r\n \"format\": \"dprint fmt\",\r\n \"setup-hooks\": \"node scripts/link-hooks.mjs\"\r\n },\r\n \"browser\": {\r\n \"fs\": false,\r\n \"os\": false,\r\n \"path\": false,\r\n \"crypto\": false,\r\n \"buffer\": false,\r\n \"@microsoft/typescript-etw\": false,\r\n \"source-map-support\": false,\r\n \"inspector\": false,\r\n \"perf_hooks\": false\r\n },\r\n \"packageManager\": \"npm@8.19.4\",\r\n \"volta\": {\r\n \"node\": \"20.1.0\",\r\n \"npm\": \"8.19.4\"\r\n }\r\n}\r\n```\r\n\r\n### Any other comments can go here\r\n\r\nI'm doing the most normal ESM-style namespace importing, which everyone would simply expect to work, even your own types think so:\r\n\r\n\r\n\r\nHowever, for some reason TS still believes that it only has to ship non-ESM files. It's 2024, why?!","author":{"url":"https://github.com/kungfooman","@type":"Person","name":"kungfooman"},"datePublished":"2024-06-10T08:38:01Z","url":"https://github.com/microsoft/TypeScript/issues/58817"}
| 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:49d29407-cef7-0960-e049-650aa0409208 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9EA4:1B10FF:1180430:16E0F09:6B04F6D4 |
| html-safe-nonce | 612df5c7ffa83546ee0e633bea1a52f3b4b5f88c360fd6a49d050613b2e21be6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RUE0OjFCMTBGRjoxMTgwNDMwOjE2RTBGMDk6NkIwNEY2RDQiLCJ2aXNpdG9yX2lkIjoiNzA1MTE3OTgxMjE0MzA4MDUyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f7f59ed62756a85c5125dc05a9172fedd16946e2fcdf16cff05f898dbcafda32 |
| hovercard-subject-tag | issue:2343260413 |
| 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/58817/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bb3170878b118e70b0b3feb4151e9cfc00ff9b5f94e15f136f5b041506fe938b/microsoft/TypeScript/issues/58817 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bb3170878b118e70b0b3feb4151e9cfc00ff9b5f94e15f136f5b041506fe938b/microsoft/TypeScript/issues/58817 |
| og:image:alt | Demo Repo https://github.com/kungfooman/ts_esm_fail Which of the following problems are you reporting? Something else more complicated which I'll explain in more detail Demonstrate the defect descr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kungfooman |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2c3971d6ab4be607cf9a26ac26ef0a7bfce380ec2ba14642e64028ad07a492b9 |
| 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 | b3f1d45dee14b3f87c64e9017a9c08d011561786 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width