npm peer dependencies for react-helmet-async package gives error using React 17

1.1k Views Asked by At

For a React 17 project, bootstrapped with create-react-app, I want to use the react-helmet-async package. This project has the following peer dependencies, located in the package.json file:

  "peerDependencies": {
    "react": "^16.6.0",
    "react-dom": "^16.6.0"
  },

When trying to install the package, the following error appears:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"^17.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.6.0" from [email protected]
npm ERR! node_modules/react-helmet-async
npm ERR!   react-helmet-async@"^1.0.7" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/bas/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/bas/.npm/_logs/2021-02-11T13_55_56_813Z-debug.log

As far as I understand, the react-helmet-async package requires React ^16.6.0 for projects using this package. I can use the --force option, which removes the error, but when I try to do an npm update it keeps recurring.

I tried adding resolutions in my package.json, trying to force the package to use the React version I'm using. Before running a npm install or npm update, I ran npx npm-force-resolutions.

  "resolutions": {
    "react-helmet-async/react": "^17.0.1"
  }

This unfortuntaly did not work. Is there any way, without downgrading to React 16, to still use this package without receiving errors in my console? Also, am I misunderstanding something about peer dependencies?

1

There are 1 best solutions below

0
On BEST ANSWER

As far as the peer dependency of react@^16 I ran out of luck other then using the --force option when installing the package. However a commit in a new version of react-helmet-async fixed the problem.