tsconfig paths and package.json#exports doesn't work together
DRANK
🔎 Search Terms paths aliases exports paths package.json#exports paths node_modules 🕗 Version & Regression Information This is the behavior in every version I tried: ~5.4, ~5.5, ~5.6, 5.7.0-beta, 5.7.1-rc, and 5.8.0-dev.20241108 ⏯ Playground Link https://stackblitz.com/edit/ts-paths-and-exports-bug?file=ts-app/tsconfig.json&file=ts-app/1-broken-with-alias.ts&file=ts-app/1-broken-with-alias.ts&view=editor 💻 Code js-package/package.json: "exports": { "./wrappers": { "types": "./lib/app-wrappers.d.ts", "import": "./lib/app-wrappers.js" } } ts-app/0-working-without-alias.ts: import { defineConfig } from 'js-package/wrappers'; ts-app/1-broken-with-alias.ts: import { defineConfig } from '#pkg/wrappers'; ts-app/tsconfig.json: { "compilerOptions": { // Use an option that respects package.json#exports "module": "Preserve", // or NodeNext (both behaves the same in this example) "paths": { "#pkg": ["node_modules/js-package"] } } } 🙁 Actual behavior TypeScript can't resolve #pkg/wrappers and fails. Adding an alias through paths doesn't respect package.json#exports. Side case: the same happens with just #pkg, so it's not just about subpaths. Unless you provide package.json#types, it doesn't work. So, it doesn't respect something like this either: "exports": { ".": { "types": "lib/index.d.ts" } } 🙂 Expected behavior I expect tsconfig paths and package.json#exports to work together. TS respects package.json#exports everywhere else fine, so it should also be working fine when using paths too. Additional information about the issue A workaround is to define a paths entry that mimics the exports entry, for every entry point needed. Example: "paths": { "#pkg/wrappers": ["node_modules/js-package/lib/app-wrappers.d.ts"], "#pkg": ["node_modules/js-package/lib/index.d.ts"], // or just `node_modules/js-package` and define `package.json#types = lib/index.d.ts` "#pkg/other-exports": ["node_modules/js-package/lib/foo.d.ts"], "#pkg/yet-another": ["node_modules/js-package/lib/bar/baz.d.ts"], }
👀🤔github.com/microsoft/Type…P