当尝试使用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来覆盖项目包中不需要的依赖项

其他回答

NPM可用于在项目中安装和管理依赖项的版本。

我在React版本和npm版本上也遇到了同样的问题:

NPM错误发现类型/react@16.14.20

因此,它可能是需要根据您的包安装的包版本。json文件。

它会在npm 7版本中给出错误,并且无法安装Node.js模块。

如果你将npm版本降级到6,这些问题将变成警告,问题将得到解决。

试着证明这个命令:npm install -g npm@6 检查版本是否已经安装:npm——version 删除并安装node_modules包: a)删除rm -rf node_modules b)安装:npm i

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

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

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

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

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