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

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

set HTTP_PROXY=
set HTTPS_PROXY=

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

更新:

执行以下命令时:

npm install --legacy-peer-deps

系统显示如下错误:


当前回答

如果它可以帮助某人,我得到这个错误,在GitHub操作,同时推送我更新的包和包锁JSON文件,

问题在于我们内部的NPM包不一致。 我必须补充一点

legacy-peer-deps=true

在我们的

npmrc。

文件来覆盖依赖项。

所以我觉得有时候最好使用legacy-peer-deps来覆盖项目包中不需要的依赖项

其他回答

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

git checkout -- package-lock.json

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

只需做两个简单的步骤:

首先,在终端中执行这个命令。

npm config set legacy-peer-deps true

其次,清除缓存:

npm cache clean --force

最后,执行你的命令。这肯定有用。

我们有同样的问题,导致错误如下:

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

首先我尝试了

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

这解决了我的问题。

在使用npm 7时,这种情况经常出现,因为对等依赖问题在版本7中被视为错误,而在版本6中通常只是警告。通常使用——legacy-peer-deps可以让它在npm 7中工作。

当这不起作用时,一个选择是降级到npm 6。降级Node.js是没有必要的(但也没有害处)。相关的依赖管理代码在npm中。降级Node.js通常是巧合,因为这样做通常也会降级npm。

另一个比降级npm破坏性更小的选择是使用npx来使用之前版本的npm的install命令:npx -p npm@6 npm install

当所有这些都失败时,通常值得尝试删除node_modules目录和包锁。Json,然后再次运行NPM install。这会重新生成node_modules和package-lock.json。