Title: Declaration emit writes an import the file cannot resolve when the package has `exports`; no TS2883 · Issue #64590 · microsoft/TypeScript · GitHub
Open Graph Title: Declaration emit writes an import the file cannot resolve when the package has `exports`; no TS2883 · Issue #64590 · microsoft/TypeScript
X Title: Declaration emit writes an import the file cannot resolve when the package has `exports`; no TS2883 · Issue #64590 · microsoft/TypeScript
Description: 🔎 Search Terms TS2883, TS2742, cannot be named without a reference, not portable, declaration emit module specifier, exports map, pnpm, import type cannot be resolved, skipLibCheck any 🕗 Version & Regression Information This is the behav...
Open Graph Description: 🔎 Search Terms TS2883, TS2742, cannot be named without a reference, not portable, declaration emit module specifier, exports map, pnpm, import type cannot be resolved, skipLibCheck any 🕗 Version & ...
X Description: 🔎 Search Terms TS2883, TS2742, cannot be named without a reference, not portable, declaration emit module specifier, exports map, pnpm, import type cannot be resolved, skipLibCheck any 🕗 Version &a...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/64590
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Declaration emit writes an import the file cannot resolve when the package has `exports`; no TS2883","articleBody":"### 🔎 Search Terms\n\nTS2883, TS2742, cannot be named without a reference, not portable, declaration emit module specifier, exports map, pnpm, import type cannot be resolved, skipLibCheck any\n\n### 🕗 Version & Regression Information\n\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about declaration emit and \"cannot be named\"\n\nTried: 6.0.3, 7.0.2, 7.1.0-dev.20261002.1.\n\n### ⏯ Playground Link\n\n_No response_ (needs a `node_modules` layout)\n\n### 💻 Code\n\nA strict `node_modules` layout, as pnpm makes it. `a` depends on `s`, `s` depends on `c`, and `a` cannot resolve `c`. The package `c` has an `exports` map with a subpath.\n\n```\nnode_modules/.store/c/node_modules/c/ package.json with \"exports\": { \"./Thing\": … }, dist/Thing.d.ts\npackages/s/node_modules/c -> the store\npackages/a/node_modules/s -> ../../s\npackages/u/node_modules/a -> ../../a\n```\n\n```ts\n// c/dist/Thing.d.ts\nexport interface Thing {\n readonly x: number;\n}\nexport declare const create: () => Thing;\n\n// packages/s/src/index.ts (composite project)\nimport { create } from \"c/Thing\";\nexport const made = create();\n\n// packages/a/src/index.ts (composite project, references s)\nimport { made } from \"s\";\nexport const thing = { made };\n\n// packages/u/src/index.ts (references a, skipLibCheck)\nimport { thing } from \"a\";\nexport const wrong: string = thing.made.x;\n```\n\n\u003cdetails>\n\u003csummary>Script that writes the project in a temporary directory and runs \u003ccode>tsc -b\u003c/code> (argument: the tsc command)\u003c/summary>\n\n```sh\n#!/bin/sh\n# usage: sh repro-1-import-out-of-reach.sh [tsc command]\nset -u\ntsc=${1:-tsc}\ncd \"$(mktemp -d)\" || exit 1\n# The physical path: on macOS the temporary directory is behind a symbolic link.\ncd \"$(pwd -P)\" || exit 1\nmkdir -p node_modules/.store/c/node_modules/c/dist packages/s/src packages/s/node_modules \\\n packages/a/src packages/a/node_modules packages/u/src packages/u/node_modules\n\ncat >node_modules/.store/c/node_modules/c/package.json \u003c\u003c'JSON'\n{\n \"name\": \"c\",\n \"version\": \"1.0.0\",\n \"type\": \"module\",\n \"exports\": {\n \"./Thing\": { \"types\": \"./dist/Thing.d.ts\", \"default\": \"./dist/Thing.js\" }\n }\n}\nJSON\ncat >node_modules/.store/c/node_modules/c/dist/Thing.d.ts \u003c\u003c'TS'\nexport interface Thing {\n readonly x: number;\n}\nexport declare const create: () => Thing;\nTS\n\nln -s ../../../node_modules/.store/c/node_modules/c packages/s/node_modules/c\nln -s ../../s packages/a/node_modules/s\nln -s ../../a packages/u/node_modules/a\n\nlibrary='{\n \"compilerOptions\": {\n \"composite\": true,\n \"emitDeclarationOnly\": true,\n \"module\": \"esnext\",\n \"moduleResolution\": \"bundler\",\n \"allowImportingTsExtensions\": true,\n \"strict\": true,\n \"rootDir\": \"src\",\n \"outDir\": \"out\"\n },\n \"include\": [\"src\"]REFERENCES\n}'\n\necho '{ \"name\": \"s\", \"version\": \"1.0.0\", \"exports\": { \".\": \"./src/index.ts\" } }' >packages/s/package.json\nprintf '%s\\n' \"$library\" | sed 's/REFERENCES//' >packages/s/tsconfig.json\ncat >packages/s/src/index.ts \u003c\u003c'TS'\nimport { create } from \"c/Thing\";\n\nexport const made = create();\nTS\n\necho '{ \"name\": \"a\", \"version\": \"1.0.0\", \"exports\": { \".\": \"./src/index.ts\" } }' >packages/a/package.json\nprintf '%s\\n' \"$library\" | sed 's#REFERENCES#,\\n \"references\": [{ \"path\": \"../s\" }]#' >packages/a/tsconfig.json\ncat >packages/a/src/index.ts \u003c\u003c'TS'\nimport { made } from \"s\";\n\nexport const thing = { made };\nTS\n\ncat >packages/u/tsconfig.json \u003c\u003c'JSON'\n{\n \"compilerOptions\": {\n \"noEmit\": true,\n \"module\": \"esnext\",\n \"moduleResolution\": \"bundler\",\n \"allowImportingTsExtensions\": true,\n \"strict\": true,\n \"skipLibCheck\": true\n },\n \"include\": [\"src\"],\n \"references\": [{ \"path\": \"../a\" }]\n}\nJSON\ncat >packages/u/src/index.ts \u003c\u003c'TS'\nimport { thing } from \"a\";\n\nexport const wrong: string = thing.made.x;\nTS\n\necho \"a depends on s; s depends on c; a cannot resolve c.\"\necho \"u assigns a number to a string, so the build must fail.\"\n$tsc -b packages/u\necho \"exit code: $?\"\necho \"packages/a/out/index.d.ts:\"\ncat packages/a/out/index.d.ts\n```\n\n\u003c/details>\n\n### 🙁 Actual behavior\n\n`tsc -b packages/u` exits with 0. The declaration of `a` is:\n\n```ts\nexport declare const thing: {\n made: import(\"c/Thing\").Thing;\n};\n```\n\n`c/Thing` cannot be resolved from `packages/a`. The consumer `u` reads `Thing` as `any`, so `const wrong: string = thing.made.x` is accepted although `x` is a number. `skipLibCheck` hides the failed import; with `skipLibCheck: false` the same build reports `packages/a/out/index.d.ts(2,18): error TS2307: Cannot find module 'c/Thing'`.\n\n### 🙂 Expected behavior\n\nTS2883 at `thing` in `packages/a/src/index.ts`. That is what all three versions report for the same layout when `c` has `\"types\": \"index.d.ts\"` and no `exports` map:\n\n```\npackages/a/src/index.ts(3,14): error TS2883: The inferred type of 'thing' cannot be named without a reference to 'Thing' from '../../s/node_modules/c'. This is likely not portable. A type annotation is necessary.\n```\n\n### Additional information about the issue\n\n- In 7.0.2, `tryGetModuleNameAsNodeModule` (`internal/modulespecifiers/specifiers.go`, about line 786) returns the specifier as soon as it comes verbatim from the package's `exports` (`if verbatimFromExports { return moduleFileToTry }`). That return is before the check that the top-level `node_modules` directory is an ancestor of the importing file, which is the check that gives an empty result, and so TS2883, in the case with no `exports` map.\n- How we found it: a workspace package had `import(\"@effect/sql-pg/PgClient\").PgClient` in a declaration and did not depend on `@effect/sql-pg`. Its consumers read a layer's requirements as `any`.\n","author":{"url":"https://github.com/kristojorg","@type":"Person","name":"kristojorg"},"datePublished":"2026-10-02T13:43:41Z","url":"https://github.com/microsoft/TypeScript/issues/64590"}
| 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:407b3bc3-dce9-23dd-b8ee-8a471be07dcf |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E56E:1087D4:9B2EE9:D06522:6B00EBD3 |
| html-safe-nonce | f1966063a604aeec6a545f70da754956ade15444ef98bfe0b24a4f6689c57df4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNTZFOjEwODdENDo5QjJFRTk6RDA2NTIyOjZCMDBFQkQzIiwidmlzaXRvcl9pZCI6IjU2NzExNTY2MTI3OTA4MDc1MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d8ca2b0568749eac99f2aff11cabc83aed6ab359abac5460ab881b7b854865e3 |
| hovercard-subject-tag | issue:5678285184 |
| 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/64590/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f7a242d1cd1f583d628ccec86da93e2df8fe448cbac46e83dad9f75e84e0ac07/microsoft/TypeScript/issues/64590 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f7a242d1cd1f583d628ccec86da93e2df8fe448cbac46e83dad9f75e84e0ac07/microsoft/TypeScript/issues/64590 |
| og:image:alt | 🔎 Search Terms TS2883, TS2742, cannot be named without a reference, not portable, declaration emit module specifier, exports map, pnpm, import type cannot be resolved, skipLibCheck any 🕗 Version & ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kristojorg |
| 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