Skip to content

[BUG] It's not possible to have workspaces with different versions of React #6040

@jfulse

Description

@jfulse

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

AFAIK It's not possible to have different workspaces with different versions of React due to hoisting.

Expected Behavior

It would be nice to be to have different versions of React in different workspaces, and upgrade different parts of the app at different times

Steps To Reproduce

  • create a new npm package with two workspaces packages/a and packages/b; its package.json including workspaces: ["packages/*"]
  • create a new app in each of the workspaces using create-react-app
  • Degrade the version in workspace a down to 17 by editing its package.json
  • Add a hook in each app, which will error if there are two versions running
  • Remove all node_modules folders, delete all package-lock.json files, and run npm 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 workspaces 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.

Environment

  • npm: 8.12.1
  • Node.js: v16.13.1
  • OS Name: macOS Bug Sur
  • System Model Name: Macbook Pro
  • npm config:
; "user" config from /Users/[REDACTED]/.npmrc

//registry.npmjs.org/:_authToken = (protected)
access = "public"

; "project" config from /Users/[REDACTED]repos/[REDACTED]/.npmrc

engine-strict = true

; node bin location = /Users/[REDACTED]/.nvm/versions/node/v16.13.1/bin/node
; node version = v16.13.1
; npm local prefix = /Users/[REDACTED]/repos/libry-content
; npm version = 8.12.1
; cwd = /Users/[REDACTED]/repos/[REDACTED]
; HOME = /Users/[REDACTED]
; Run `npm config ls -l` to show all defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions