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

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

set HTTP_PROXY=
set HTTPS_PROXY=

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

更新:

执行以下命令时:

npm install --legacy-peer-deps

系统显示如下错误:


当前回答

在这个案子上,我遇到了问题

无法解析依赖树

在一个Angular 13项目中,它使用了Azure DevOps中私有npm提要中的一些包。

为了访问这个存储库,我创建了一个.npmrc文件。正因为如此,npm install命令将搜索我的私有存储库中的所有包,而不再是npm feed中的包。无法解决依赖树错误是因为npm install命令找不到很多托管在npm提要而不是我的私有提要中的包。

我找到了一个关于如何确定包范围的惊人答案。

在此基础上,我做了一些修改:

在我的图书馆包里。Json,更新名称有一个作用域名@mylib “名称”:“@myLib /命令队列”, 构建并将此包发布到我的私人提要 在我的客户端应用程序(使用这个包的应用程序)中,更新.npmrc文件,只对这个范围内的包使用我的私有提要 @myLib:注册表= https://pkgs.dev.azure.com/..。 always-auth = true

现在,每当我运行npm install命令时,如果包的作用域是@myLib,它就会在我的私有提要中查找它,并在所有其他情况下使用npm提要(即@angular/…)

这是我的客户端应用程序包的一个例子。json文件:

    "@angular/platform-browser-dynamic": "~13.3.0",
    "@angular/router": "~13.3.0",        <-- this comes from npm
    "@myLib/jcg-command-queue": "^2.2.0", <-- This comes from my private feed

而且,有了这个改变,就不需要再在npm install命令中添加——legacy-peer-deps了。

其他回答

尝试删除节点模块和包锁。Json文件,运行命令NPM install 或 试试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可用于在项目中安装和管理依赖项的版本。

我在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

问题似乎是gf-kautomata-pipeline-ui使用的是Angular 9,而@angular/http需要Angular 7。(@angular/http已经弃用并最终被移除,它的所有功能都被移到了@angular/common中。)

见:https://www.npmjs.com/package/@angular http

如果你运行的是Angular 9,那么

从包中删除@angular/http。json(在Angular 9中你不需要它) 确保你的package.json中有@angular/common。 运行npm i。

如果你运行的是Angular 7,那么打开你的包。检查并确保你所有的Angular包都不高于^7.0.0。你可能还需要删除gf-kautomata-pipeline-ui,或者联系gf-kautomata-pipeline-ui的作者,看看这个库是否与Angular 7兼容。

首先我尝试了

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

这解决了我的问题。