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

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

set HTTP_PROXY=
set HTTPS_PROXY=

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

更新:

执行以下命令时:

npm install --legacy-peer-deps

系统显示如下错误:


当前回答

把Node.js降级到v14适合我。

使用这些命令:

source ~/.bash_profile
nvm use v14.16.1
npm install

其他回答

试试这个命令-

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

把Node.js降级到v14适合我。

使用这些命令:

source ~/.bash_profile
nvm use v14.16.1
npm install

在我的例子中,我从版本6升级到版本7后开始得到错误(如下所示)。

npm犯错!ERR!无法解析依赖项 树 ... npm犯错!修复上游依赖项冲突,或使用——force或——legacy-peer-deps重试此命令,以接受错误的(可能损坏的)依赖项解决方案。

在我的例子中,使用——legacy-peer-deps或——force标志进行编译会导致一个无用的包。

所以我试着删除node_modules, package-lock。Json和bundle使用yarn install。这就产生了纱线。锁定文件和创建的包锁。Json,在后续的NPM运行中工作良好。

附注:我正在使用临时的解决方法,直到npm 7对我的项目起作用:在那之后,我将删除yarn。锁,package-lock。Json和node_modules文件夹,然后用NPM重新编译

rm -rf node_modules
rm package-lock.json
yarn install
# Generates a yarn.lock file and a new package-lock.json

# Continue with npm
npm start

您可以使用显示此错误的两种方式安装包

ERESOLVE unable to resolve dependency tree

使用npm Install并使用——legacy-peer-deps安装包

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

这是两个命令的组合 a.在npm config中设置legacy-peer-deps为true NPM配置设置为true b.现在使用npm install安装包 npm安装

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