-
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
TypeScript module versions conflicts #33137
Comments
I've still having problems with TypeScript and types resolution, not only with monorepositories: As i said, npm allows to install more than one breaking change version installed (usually the older one is installed in specific modules and newer in node_modules root) and TypeScript stills having problems with modified types and interfaces. This problem could be extended to all the community in the future due to not all developers have the most recent version of all modules. As more typescript modules you have installed the risk is increased due to more version modules exists in your node modules. The issue seems to be also related to this commit #33567. While using "traceResolution" option in compiler options, node resolution behavior seems to be right, it goes from the file to the project root looking for on each iteration "./node_modules/module" but, somehow types are like "stored" in a paths cache which confuses module folders. I've seen sometimes VSCode telling that there are multiple matches with a module absolute import path (Maybe should select the closest one). |
@imt-jaime Can you please update your repro and see if it still repros.. I followed exact steps in your repro and I get completely different error: Here are the steps I followed:
|
Hello @sheetalkamat , i've updated the repository to version 3.7.5 (current) and it stills happening. The steps to reproduce the issue were the same except for the last one (npm run typescript which is tsc command). However the error ive found is different from yours, it seems link didn't installed module-b dependencies. Maybe you missed to install project dependencies? (npm install at root) Correction: Thats the error I get by running typescript: src/packages/ts-issue-module-a/src/index.ts:5:5 - error TS2322: Type 'string' is not assignable to type 'number'.
5 age
~~~
node_modules/ts-issue-module-b/node_modules/ts-typelib-example/src/index.ts:2:3
2 age: number;
~~~
The expected type comes from property 'age' which is declared here on type 'SomeInterface'
Found 1 error. Additional Information: Working in another projects stills the same error, I think typescript creates a libraries cache like and selects randomly what library to check avoiding node_resolution without taking care of versions or node_modules structure. |
@imt-jaime thank you for correcting the repro.. I will investigate this.. |
Error is exactly what you said. TypeScript can confuse modules from ancestors or even modules in another branches. I am sorry about the complexity of the repository. It is a complex error but i think it is the minimal reproduction of the error. |
Well from typescript perspective that is intended behavior though.. The error looks correct based on how the resolution works with the folder structure present in the repro scenario.. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
If anyone find this issue, it seems fixed on the |
Fixed by |
I had this issue because one of my dependencies (A) had a peerDependency listed as B@0.1.8 and I had to use B@0.2.0 in my root package. I first tried using selective version resolutions to force A into using B@0.2.0, but that didn't work (it could work for you if you use semver compatible versions). What I ended up doing is installing B@0.2.0 in my root package as an alias, so that there is no conflict on types because it will be treated as a different package in a different namespace. Then you just need to be careful not to mix B@0.1.8 and B@0.2.0 types in your code. |
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
types conflict
modules conflict ts(2742)
duplicate modules
module versions conflict
monorepo modules conflict
Code
index.ts (main project)
ts-module-b (linked package module)
ts-module-a (module-b dependency)
For
SomeInterface
it exists in 2 versions: (1.0.0) where age is a string and (2.0.0) where age is a number. (breaking change version.Expected behavior:
The expected behaviour is that the returned interface by moduleB should be the 2.0.0 version interface (as expected from node_modules resolution first level). Instead, VSCode displays an error telling to import SomeInterface to resolve the conflict.
Actual behavior:
TypeScript cannot resolve the type returned by the moduleB function creating undesirable errors in dependencies. (This error could exist in thousands of dependencies due to developers cant update 2nd level dependencies from third party modules).
Playground Link:
https://github.com/imt-jaime/ts-monorepo-issue-example
Related Issues:
#29221
** Repository Structure **
The text was updated successfully, but these errors were encountered: