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

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

set HTTP_PROXY=
set HTTPS_PROXY=

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

更新:

执行以下命令时:

npm install --legacy-peer-deps

系统显示如下错误:


当前回答

只需做两个简单的步骤:

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

npm config set legacy-peer-deps true

其次,清除缓存:

npm cache clean --force

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

其他回答

在我的例子中,我遇到了@babel/core依赖的问题,但我不想使用——force,因为我不确定后果,所以我去https://www.npmjs.com/,寻找包并用最新的包替换了我的旧版本。这就成功了。

尝试以下两种方法来解决此问题:

选项1:删除文件夹“node_modules”和文件“package_lock”。Json: NPM cache clean -force after NPM I -force 选项2:执行npm install——save——legacy-peer-deps命令

某些包在更新到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

或者只是等待,直到这些软件包更新。

该问题与依赖冲突或破坏的依赖有关。您可以通过强制安装来接受依赖项的错误。

解决方案:使用命令——force。

你的命令应该像npm install——force @your-npm-package。

注意:如果在yarn包管理器中安装依赖项可用,则可以使用yarn安装依赖项。

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

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