简体   繁体   English

npm 安装 - ERESOLVE 无法解析依赖树

[英]npm install - ERESOLVE unable to resolve dependency tree

I am trying to npm install but getting this error.我正在尝试npm install但收到此错误。

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: webapp@21.0.0
npm ERR! Found: @angular/cdk@9.2.4
npm ERR! node_modules/@angular/cdk
npm ERR!   @angular/cdk@"9.2.4" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/cdk@"8.2.3" from @angular/material@8.2.3
npm ERR! node_modules/@angular/material
npm ERR!   @angular/material@"8.2.3" 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 updated node.js to the latest recommended LTS version which is currently version 14. This is what is causing the problem.我将 node.js 更新为最新推荐的 LTS 版本,目前是版本 14。这就是导致问题的原因。

I tried using --force and --legacy-peer-deps , but this didn't work.我尝试使用--force--legacy-peer-deps ,但这没有用。

The solution is to downgrade the node version to 12.解决办法是降级node版本到12。

Here is a copy/paste solution to fix.这是要修复的复制/粘贴解决方案。 Copy all of this code and paste in the terminal at the root of your project.复制所有这些代码并粘贴到项目根目录下的终端中。 (Where your package.json file that you are trying to install is.) (您尝试安装的package.json文件所在的位置。)

rm package-lock.json
rm -rfv node_modules
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 12
nvm use 12
npm i

What is happening here?这里发生了什么?

  1. Remove the package-lock.json file删除package-lock.json文件
  2. Remove the node_modules directory ( -rfv = recursive, force, verbose)删除node_modules目录( -rfv = recursive, force, verbose)
  3. Install nvm (Node Version Manager)安装nvm (节点版本管理器)
  4. Configure nvm配置nvm
  5. Load nvm加载nvm
  6. Use nvm to install node v12使用nvm安装 node v12
  7. Tell this project to use node v12告诉这个项目使用节点 v12
  8. Use npm to install the packages使用npm安装软件包

try npm install --legacy-peer-deps .尝试npm install --legacy-peer-deps This worked for me.这对我有用。 But first make sure you delete your package-lock.json and node_modules .但首先确保删除package-lock.jsonnode_modules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM