You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{"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"],
}
The text was updated successfully, but these errors were encountered:
π Search Terms
π Version & Regression Information
~5.4
,~5.5
,~5.6
,5.7.0-beta
,5.7.1-rc
, and5.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
:ts-app/0-working-without-alias.ts
:ts-app/1-broken-with-alias.ts
:ts-app/tsconfig.json
:π Actual behavior
TypeScript can't resolve
#pkg/wrappers
and fails. Adding an alias throughpaths
doesn't respectpackage.json#exports
.Side case: the same happens with just
#pkg
, so it's not just about subpaths. Unless you providepackage.json#types
, it doesn't work. So, it doesn't respect something like this either:π Expected behavior
I expect tsconfig
paths
andpackage.json#exports
to work together. TS respectspackage.json#exports
everywhere else fine, so it should also be working fine when usingpaths
too.Additional information about the issue
A workaround is to define a
paths
entry that mimics theexports
entry, for every entry point needed. Example:The text was updated successfully, but these errors were encountered: