当尝试使用npm i命令安装npm包时,我得到了以下异常:
我尝试重新安装Node.js包,并使用以下方法将代理设置为关闭:
set HTTP_PROXY=
set HTTPS_PROXY=
问题仍然存在。我哪里做错了?
更新:
执行以下命令时:
npm install --legacy-peer-deps
系统显示如下错误:
当尝试使用npm i命令安装npm包时,我得到了以下异常:
我尝试重新安装Node.js包,并使用以下方法将代理设置为关闭:
set HTTP_PROXY=
set HTTPS_PROXY=
问题仍然存在。我哪里做错了?
更新:
执行以下命令时:
npm install --legacy-peer-deps
系统显示如下错误:
当前回答
这个问题我已经遇到过很多次了。最后我找到了一个解决方案:
npm install react-native-paper --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
这解决了我的问题。
在我的例子中,我从版本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
某些包在更新到npm 7后会出现这种情况。
参数——legacy-peer-deps可以帮助:
npm i --legacy-peer-deps
此处描述legacy-peer-deps
导致npm在构建peerDependencies时完全忽略 包树,如NPM版本3到6。 如果一个包因为过于严格而无法安装 碰撞的peerDependencies,它提供了一种前进的方式 解决问题。 ...
你可以在默认情况下将这个选项设置为true (npm不推荐):
npm config set legacy-peer-deps true
或者只是等待,直到这些软件包更新。
我们有同样的问题,导致错误如下:
npm犯错!代码erresolve npm 犯错!erresolve无法解析npm 犯错! npm犯错!解析时:@angular/material-moment-adapter@12.1.4 npm 犯错!发现:@angular/material@12.0.6 npm ERR! node_modules/@angular/material@angular / material@”~ 12.0.4” 从根项目开始 ...
我们在Azure-Pipelines中使用npm ci进行清洁安装。
问题经常出在那个包裹上。Json和包锁。Json不再同步。
解决方案是执行npm install local并推送新的package-lock.json。
作为额外的提示,我们在管道中添加了一个新任务,以便在作业失败时获得额外的信息。
- task: Npm@1
displayName: npm install
inputs:
command: custom
customCommand: ci
customRegistry: useNpmrc
# ##vso[task.logissue type=error] writes the text to the summary page (error-log).
- bash: echo "##vso[task.logissue type=error] If 'npm install' fails with 'ERESOLVE could not resolve', 'package.json' and 'package-lock.json' (needed for 'npm ci') may be out of sync. Run 'npm install' locally and push the new package-lock.json."
condition: failed() # Only execute on fail
displayName: npm install failed hint
重置package-lock。Json一直都很适合我:
git checkout -- package-lock.json
细节: 在更新遗留项目的所有包时,我经常遇到这种情况——我强烈不建议使用npm审计fix或npm I——force。删除包锁。Json也并不总是适用于我。回滚到包的工作版本。Json +包锁。Json和添加包对我来说是最安全、最快的变体。