-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[BUG] using a workspace instead of a separate repo leads to having 2 react versions instead of 1 #4557
Comments
from this #2924 i learned that there is a So please, please, please, could someone knowing what is going on here document this in the official documentation? |
The reason this is happening is because |
@wraithgar thanks for your answer. I have a monorepo where some of the packages are react component libraries. There are other packages in this monorepo using these components they have a specific react version they use and have the react component packages as dependencies. BUT how to include the component packages here? Deploying to a local repo and using them in a specific version is not practical solution (every small change requires publishing a version ), linking to them via file: has the big disadvantage, that the dev dependencies are also installed (since it is a link to the node_modules of the react component in dev mode) wich leads again to 2 versions of react... From your answer I understand that workspaces and plain npm install doesn't work either. npm install --global-style worked in my case BUT I'm not sure if this always will work or if this was just a lucky coincidence... For me it looks like we desperately need 3 subfolders under node_modules, dependencies, devDependencies and peerDependencies and the file: protocol links only to the node_modules/dependencies folder ... Or is there anything else I have missed? Thanks |
Are you trying to make sure everything gets the same version of react, or everything gets the same copy of react? There isn't any real way to guarantee that every module in your tree is getting the same identical copy of a dependency they require as the other modules. The nature of hoisting and deduping makes this so. Relying on this is bound to have issues. If you need everything to have the exact same version of react, perhaps overrides could be a path forward for you. |
As far as I understand, npm should "only" ensure the same version of react as a dependency of all packages, webpack assures then, that there is only a single instance of react in the app. Some more info is here. Looks like "yarn resolutions" is the same like "npm overrides" (and I have somehow missed that...) I'll try now to switch to overrides and report back. Thanks |
I switched back from workspaces to the default behavior. I tried overrides for one of the packages but they don't help, since monorepo dependencies are linked, and linked means directory link. And if some sub-dependency is installed (no matter if normal or dev dependency) then it is there. |
That would be a pretty significant change to how workspaces work and would need to go through the rfc process. Closing this now as it things are currently working as designed, and changing it would mean changing the design. |
Hey @Ognian |
@daksh-sagar as mentioned in my previous comment I'm not using workspaces anymore, and by reducing package dependencies my apps work now. I don't think that there will be any other solution for this problem. |
cool |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
and we see here 2 versions of react wich is wrong
Expected Behavior
I would expect the same behavior as if it would be without a workspace
This is a reduced test case. The actual problem is more complex, there are 2 workspaces with different react versions and no react dependency in the root. Other workspaces no react but they are dependencies of the react ones (so I need workspaces).
Steps To Reproduce
see above
Environment
The text was updated successfully, but these errors were encountered: