npm install - ERESOLVE 无法解析依赖关系树

Mat*_*att 11 node.js npm angular

我正在尝试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.
Run Code Online (Sandbox Code Playgroud)

Mat*_*att 9

我将 node.js 更新到最新推荐的 LTS 版本,当前版本为 14。这就是导致问题的原因。

我尝试使用--forceand --legacy-peer-deps,但这不起作用。

解决方案是将node版本降级到12。

这是要修复的复制/粘贴解决方案。复制所有这些代码并粘贴到项目根目录的终端中。(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
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?

  1. 删除package-lock.json文件
  2. 删除node_modules目录(-rfv=递归、强制、详细)
  3. 安装nvm(节点版本管理器)
  4. 配置nvm
  5. 加载nvm
  6. 用于nvm安装节点v12
  7. 告诉这个项目使用node v12
  8. 用于npm安装软件包


小智 8

尝试npm install --legacy-peer-deps。这对我有用。但首先请确保删除您的package-lock.jsonnode_modules