Preface
Dependency management is an indispensable part of modern front-end project development. Then, due to various problems, such as historical reasons and lack of maintenance of projects, front-end projects will encounter many problems in dependency management. This article discusses one of these,npm install
An error was encountered whileERESOLVE unable to resolve dependency tree
The cause of the problem and how to solve it.
Report an error message
Installed in one[email protected]
Installation dependencies in the projectali-react-table
, the following error will appear. If you read the cause of the error carefully, you can know theali-react-table
Used inpeerDependencies
Defined dependenciesreact@"^16.8.0 || ^17.0.1"
Projects, and our projectsReact
Version numbers conflict. Although this is becauseali-react-table
We have neglected maintenance and have not updated the dependency version information, but our controllability of third-party dependencies is relatively low, except waiting for third-party dependencies to be updated or raisedPR
Waiting for the merge to release the version, we have some other ways to temporarily solve this problem.
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@"^18.2.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react@"^16.8.0 || ^17.0.1" from [email protected] npm ERR! node_modules/ali-react-table npm ERR! ali-react-table@"*" 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.
Plan 1: Downgrade
Dependency rules verification isnpm@7
After that, we can downgradeor
npm
If you bypass the verification, you will not report an error.
nvm use 14.17.4 ## or npm i -g npm@6
Solution 2: -f or --legacy-peer-deps
Actually, we knowali-react-table
Due to neglecting maintenance, the dependency version information was not updated in time. Actual tests and our project[email protected]
It can run without any problems, so we can bring it with us when installing it--force
Parameters (abbreviated-f
)Tellnpm
Forced installation.
npm install -f
Another parameter is--legacy-peer-deps
, no need to downgradenpm
Letnpm install
The behavior is the same as the old version,Reference Documents. However, the actual use effect of this parameter may vary depending on the project and need to be tested by yourself.
npm install --legacy-peer-deps
Solution 3: yarn's solutions or npm's overrides
There may be more than one similar project in actual projectsali-react-table
The problem of inconsistent dependency version and the dependency version required by the project may have many dependencies. Sometimes we know the dependency version relationship of the project, and you can use it.resolutions
(Use onlyyarn
Only use itReference Documents) oroverrides
(onlynpm@8
Only use the aboveReference Documents) to specify and overwrite the dependent version specified by the third-party package. This parameter is also very effective in some other scenarios, such as the required third-party dependencies are lacking maintenance, and the specified version is a problematic version.
{"name": "project","version": "1.0.0","dependencies": {},"resolutions": {"react": "^18.2.0"} }
{"overrides": {"react": "^18.2.0"}}
Summarize
Dependency management is now an important part of front-end development. In addition to timely paying attention to third-party dependency version updates and large-scale version updates.Breaking Change
In addition to whether it is compatible with your own project, you should also select appropriate third-party dependencies for your own project and update the dependency version in a timely manner to avoid the dependency version problem affecting project development and project operation. When encountering an error, you should see the error instructions clearly and find out the root cause of the error, and prescribe the right medicine to find the appropriate solution.
This is the article about the solution to the npm installation dependency error ERESOLVE unable to resolve dependency tree. This is the end. For more related contents of npm installation dependency error ERESOLVE, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!