这与HTTP代理无关。
正如它所说,您有依赖冲突(不正确且可能是损坏的依赖项),因此请尝试使用--force
或--legacy-peer-deps
命令运行。如果没有效果,临时解决方案是使用先前版本的Node.js(降级Node.js版本),因为有时会导致这种错误的发生。
根据OP的更新进行更新:
如您所见,它触发了以下错误:
@angular/http@^9.1.4没有匹配版本。
请查看angular/http
页面。注意,该废弃包的最新版本为7.2.16
,而您请求更高版本(例如^9.1.4
)!因此,请检查项目依赖项并遵循引发的错误以解决问题。
--force
和 --legacy-peer-deps
命令的输出结果。 - Amirhossein Mehrvarzinpm install --legacy-peer-deps
对我很有用。 - Gaurav Patilnpm install --save --legacy-peer-deps
首先要理解问题。以下是我遇到的错误:
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: project-admin@11.0.0
npm ERR! Found: @angular/common@11.0.3
npm ERR! node_modules/@angular/common
npm ERR! @angular/common@"11.0.3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^9.1.0 || ^10.0.0" from @agm/core@3.0.0-beta.0
npm ERR! node_modules/@agm/core
npm ERR! @agm/core@"3.0.0-beta.0" from the root project
首先,您应该从底部向上阅读问题。这里 @agm/core@3.0.0-beta.0 要求 angular common 的版本为 9.1.0 或 10.0.0。而顶部信息显示找到的 angular common 版本实际上是 11.0.3。
(如果您想更好地理解依赖关系,请参阅此简单网站:如何使用 npm3)
dependencies — these are the essential dependencies that you rely on and call in your project’s code
devDependencies — these are your development dependencies, for example, a prettier library for formatting code
peerDependencies — if you set a peer dependency in your package.json, you are telling the person who installs your package that they need that dependency with the specified version
optionalDependencies — these dependencies are optional and failing to install them will not break the installation process
bundledDependencies — it’s an array of packages that will come bundled with your package. This is useful when some 3rd party library is not on NPM, or you want to include some of your projects as modules
那么应该怎么解决呢? 问题在于对等依赖项。 解决方案是降级 angular common 或者 使用--legacy-peer-deps 逻辑来安装包的旧版本依赖项。 因此,--legacy-peer-deps 不会尝试自动安装 peerDependencies。这对您有用吗? 可能是,但您应该添加特定说明以了解如何执行此操作,或者使使用 --legacy-peer-deps 自动进行将来的项目包安装。使用来自之前答案之一的代码:
npm config set legacy-peer-deps true
在我的情况下,我安装了这个包并尝试运行ng serve
,但是因为使用了--legacy-peer-deps,一些依赖包没有被安装。我不得不手动安装它们(因为我没有从上面的代码中设置配置)。最后,手动安装了大约五个带有--legacy-peer-deps的包,最后遇到了一个无法安装的包,而且我的项目也会抛出很多警告,并且还有许多要审核的包。所以我的决定是不使用这个包,寻找替代方案。
我在途中读到的其他解决方案:
npm config set legacy-peer-deps true
是魔法,谢谢! - Jeb50除了使用 --legacy-peer-deps
命令行选项外,这也可以作为配置选项更加永久地设置:
npm config set legacy-peer-deps true
npm install
是间接运行的,例如通过脚本,最佳选项是什么。 - kszl当使用 npm
7 时,由于同行依赖的问题在版本7中被视为错误而不是警告,因此经常会出现此问题,通常使用 --legacy-peer-deps
可以使其在 npm
7 中正常工作。
如果以上方法无效,另一种选择是降级到 npm
6。降级 Node.js 不是必需的(但也没有害处)。相关的依赖管理代码位于 npm
中。降级 Node.js 往往会起作用,因为这样做通常也会降级 npm
。
比降级 npm
更少干扰的另一种选择是使用 npx
来仅针对 install 命令使用之前版本的 npm
:npx -p npm@6 npm install
当所有方法都失败时,通常值得尝试删除 node_modules
目录和 package-lock.json
文件,然后再次运行 npm install
。这将重新生成 node_modules
和 package-lock.json
。
首先,在您的终端中执行此操作。
npm config set legacy-peer-deps true
其次,清除缓存:
npm cache clean --force
最后,执行你的命令。
在更新到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
可以用于安装和管理项目依赖的版本。
我在使用React版本时遇到了与npm版本相关的同样的问题:
npm错误发现types/react@16.14.20
因此,可能需要根据您的package.json文件安装包版本。
它在npm 7版本中会产生错误,并且无法安装Node.js模块。
如果您将npm版本降级为6,这些问题将变成警告,问题将得到解决。
尝试运行以下命令:npm install -g npm@6
检查是否已安装版本:npm --version
删除并安装node_modules包:
a)删除 rm -rf node_modules
b)安装: npm i
npm install
,这对我起作用了。 - Huzaifa