当尝试使用npm i命令安装npm包时,我得到了以下异常:

我尝试重新安装Node.js包,并使用以下方法将代理设置为关闭:

set HTTP_PROXY=
set HTTPS_PROXY=

问题仍然存在。我哪里做错了?

更新:

执行以下命令时:

npm install --legacy-peer-deps

系统显示如下错误:


当前回答

首先我尝试了

npm install

它给了我一个错误,无法解决依赖树,根据这个命令的帮助信息,

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 install --legacy-peer-deps

这解决了我的问题。

其他回答

Use

npm install --legacy-peer-deps

这对我很管用。

以防万一,当我尝试npm升级当前的Angular 11时,我确实有类似的行为。或者基于Angular 12.x创建新的ng new abc。我只是忘了升级Angular CLI。所以这个npm install -g @angular/cli@latest解决了我在ng new abc期间的错误。

试试这个命令-

npm install --save --legacy-peer-deps

尝试删除节点模块和包锁。Json文件,运行命令NPM install 或 试试npm cache clean——force

重置package-lock。Json一直都很适合我:

git checkout -- package-lock.json

细节: 在更新遗留项目的所有包时,我经常遇到这种情况——我强烈不建议使用npm审计fix或npm I——force。删除包锁。Json也并不总是适用于我。回滚到包的工作版本。Json +包锁。Json和添加包对我来说是最安全、最快的变体。