Home > Software engineering >  Why npm install keeps giving dependency error?
Why npm install keeps giving dependency error?

Time:04-06

While running npm install i got the following error:

While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"17.0.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^0.14.9 || ^15.3.0 || ^16.0.0" from [email protected]
npm ERR! node_modules/react-quill
npm ERR!   dev react-quill@"1.3.5" 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.

I tried removing package-json and deleting node modules and reinstalling them but still couldn't solve it. Please give me suggestion on how to fix it.

CodePudding user response:

It seems react-quill 1.3.5 uses React ^16.0.0 and not React ^17.0.0 as a dependency while you are running React v17.

From this other post :

Due to the large number of modules that haven't specifically added React v17 as a peerDependency, it's now commonplace to encounter the unable to resolve dependency tree error when running npm installs within a v17 React application.
This error will fire whenever a module (or any of its own dependencies) lists a previous version of React as a peerDependency without specifically including React v17 as well.

The newer version of react-quill (v2.0.0-beta) is using React v17 so one option would be to install it.

npm install react-quill@beta

See repository issue

CodePudding user response:

You have a dependency tree conflict. Follow this:

  1. Delete Packagelock.json
  2. Delete Node Modules.
  3. Update the version of react -quill in package.json to react-quill@beta OR Update the version of react-quill to beta as it supports react 17 using npm update react-quill@beta
  4. Run npm i adn then npm start
  • Related