-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
typeVersions
substitution occurs multiple times causing resolution to fail
#41284
Comments
- "*" match seems to cause multiple path substitutions microsoft/TypeScript#41284 that packge name prefix seems to resolve - add types field which acts as main in TS
- modify scripts to use newer tsc --bulid command - generate types on prepare so linking to git dependency works - workaround douple substitution by mapping types/* to itself (see microsoft/TypeScript#41284)
- "*" match seems to cause multiple path substitutions microsoft/TypeScript#41284 that packge name prefix seems to resolve - add types field which acts as main in TS
- modify scripts to use newer tsc --bulid command - generate types on prepare so linking to git dependency works - workaround douple substitution by mapping types/* to itself (see microsoft/TypeScript#41284)
- "*" match seems to cause multiple path substitutions microsoft/TypeScript#41284 that packge name prefix seems to resolve - add types field which acts as main in TS
- modify scripts to use newer tsc --bulid command - generate types on prepare so linking to git dependency works - workaround douple substitution by mapping types/* to itself (see microsoft/TypeScript#41284)
- "*" match seems to cause multiple path substitutions microsoft/TypeScript#41284 that packge name prefix seems to resolve - add types field which acts as main in TS
- modify scripts to use newer tsc --bulid command - generate types on prepare so linking to git dependency works - workaround douple substitution by mapping types/* to itself (see microsoft/TypeScript#41284)
- "*" match seems to cause multiple path substitutions microsoft/TypeScript#41284 that packge name prefix seems to resolve - add types field which acts as main in TS
- modify scripts to use newer tsc --bulid command - generate types on prepare so linking to git dependency works - workaround douple substitution by mapping types/* to itself (see microsoft/TypeScript#41284)
- "*" match seems to cause multiple path substitutions microsoft/TypeScript#41284 that packge name prefix seems to resolve - add types field which acts as main in TS
- modify scripts to use newer tsc --bulid command - generate types on prepare so linking to git dependency works - workaround douple substitution by mapping types/* to itself (see microsoft/TypeScript#41284)
Ran into this recently. Also happens with directly adding "typesVersions" to package.json and using any wildcards. This may effect more people than the OP (which had package references and such), so here's an example repo if helpful: https://github.com/paulnelson2/import-from-types-versions-package-bug-typescript DetailsWith typesVersions: {
"typesVersions": {
"*": {
"*": [
"src/*"
]
}
}
} and a file at Actual behaviorFails trying to import "(pkg)/fails" First it tries: Expected behavior:Instead to try Entire relevant traceResolution section:
|
Workaround: Instead of {
"typesVersions": {
"*": {
"*": ["src/*"]
}
}
} do {
"typesVersions": {
"*": {
"*": ["src/*"],
"src/*": ["src/*"]
}
}
} This turns the second expansion into a no-op. |
@pauldraper THANK YOU! This has been vexing me for months! |
TypeScript Version: 4.0.3, 4.1.0-dev.20201027
When module direcotry is imported which is mapped to typedefs through
typeVersions
typescript ends up doing path substitution multiple times and ends up with a wrong lookup path leading to failed resolution. I have created minimal reproducible example https://github.com/Gozala/bug-tsc-path-substitution/tree/double-substitutionWhere you can see that
src/index.ts
importsbar/src
module which seems to do the following:node_modules/bar/dist/src.ts
node_modules/bar/dist/src.tsx
node_modules/bar/dist/src.d.ts
node_modules/bar/dist/src/index.(ts,tsx,d.ts)
it seems to look at 'package.json' 'main' field and do second path substitution:dist/src/dist/src/index
instead ofdist/src/index
.bar/src
in place ofbar
as illustrated bynode_modules/foo/
where original import was forbar
but typedefs emitted havebar/src
instead (for no apparent reason)Search Terms:
Code
Expected behavior:
After considering following paths:
node_modules/bar/dist/src.ts
node_modules/bar/dist/src.tsx
node_modules/bar/dist/src.d.ts
Following paths should be considered
node_modules/bar/dist/src/index.ts
node_modules/bar/dist/src/index.tsx
node_modules/bar/dist/src/index.d.ts
Actual behavior:
Instead after considering following paths
After considering following paths:
node_modules/bar/dist/src.ts
node_modules/bar/dist/src.tsx
node_modules/bar/dist/src.d.ts
TS seems to do another path substitute for
dist/src/index.js
ends up with wrong pathnode_modules/bar/dist/src/dist/src/index.js
which cases failure in findingdist/src/index.d.ts
Playground Link:
Can't demonstrate with playground, as many files are involved. Please see demo repo instead
https://github.com/Gozala/bug-tsc-path-substitution/tree/double-substitution
Related Issues:
/src
to otherwisebar
imports (which don't exhibit this problem). Which on it's own seems surprising making this a lot more problematic.The text was updated successfully, but these errors were encountered: