Skip to content
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

Use overrides to fix reflux peerDependency resolution #4704

Merged
merged 1 commit into from
Nov 2, 2023

Conversation

p2edwards
Copy link
Contributor

@p2edwards p2edwards commented Oct 26, 2023

Description

Make reflux use the project-level version of React to resolve its peerDependency.

With this change, --legacy-peer-deps will no longer be needed when installing with npm >= 8.6.0.

Related issues

Part of #4703

Notes

Reflux specifies "react": "^15.0.2" as a peerDependency. We use a newer major version of React. Starting with npm@8.6.0, this would start to break npm install. More information: npm/cli: npm ci validates package-lock.json and could fail to resolve

The error you'd see when using npm >= 8.6.0 looked like:

  npm ERR! code ERESOLVE
  npm ERR! ERESOLVE could not resolve
  npm ERR!
  npm ERR! While resolving: reflux@6.4.1
  npm ERR! Found: react@16.13.1

Using overrides in package.json (added to npm in npm 8.3.0)

    "overrides": {
      "reflux": { "react": "$react"}
    },

tells npm that Reflux should use our project-level version of React to resolve its dependency on "react" — even though our project-level React (16) falls outside of the semver range that Reflux wants (^15.0.2).

    "overrides": {
      "reflux": { "react": "$react"}
    },

This tells npm that Reflux should use our project-level version of React
to resolve its dependency on "react". This override applies even though
our project-level React (16) falls outside of the semver range that
Reflux wants (^15.0.2).

Alternatively, this would work:

    "overrides": {
      "react": "$react"
    },

However, the next time we upgrade React, I'd like to see warnings from
other libraries (if applicable) so we can be sure to upgrade them.

We override this for Reflux because it's not likely to receive updates,
yet it tends to continue to work with newer versions of React without
any problem.

References:

  overrides on npm
  https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides

  Helpful comment on the Node breakage thread
  npm/cli#4998 (comment)

The error you'd see when using npm >= 8.6.0 looked like:

  npm ERR! code ERESOLVE
  npm ERR! ERESOLVE could not resolve
  npm ERR!
  npm ERR! While resolving: reflux@6.4.1
  npm ERR! Found: react@16.13.1
Copy link
Contributor

@LMNTL LMNTL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works well after some testing - none of the functionality that depends on Reflux appears to be affected. Looking through GitHub, it appears that others have successfully run Reflux in production doing versions of what you're doing - see reflux-react-16. Thank you!

@p2edwards p2edwards merged commit 0d17a87 into beta Nov 2, 2023
4 checks passed
@p2edwards p2edwards deleted the npm-override-reflux-react branch November 2, 2023 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants