We would like to have a workspace with different versions of react in two npm packages of the same workspace, due to one of them having dependencies not yet compatible with v18. However we're not able to do this without one of the versions being hoisted up to the root level, causing issues for the app in the other package.
At least I think that's what's going on. A simple reproduction goes as follows:
- Create a new npm workspace with two packages,
packages/a
andpackages/b
; the rootpackage.json
includingworkspaces: ["packages/*"]
- Create a new app in each of the workspace packages using
create-react-app
- Degrade the version in workspace
a
down to 17 by editing itspackage.json
- Add a hook in each app, which will error if there are two versions running
- Remove all
node_modules
folders, delete allpackage-lock.json
files, and runnpm i
in the root folder - Start the two apps. This gives the "several versions of react" error with the hooks. Examining the
node_modules
folder in the root level we see that it contains one of the react versions - We also tried running
npm i
in each of the packages separately with the same result
In addition we tried creating a similar setup but without the full app, only installing (different versions of) react
and react-dom
in the two; still the root level node_modules
contains one of them.
Lastly we tried using --legacy-bundling
, but we haven't been able to make it work; also we're not sure it's worth the cost.
Is there a way to have a workspace with two different versions of react?
npm install --install-strategy=linked
:) – Horsehairnpm ls
, which has "invalid" errors). Might come back to it and investigate more later – Chignon