[英]Fix the upstream dependency conflict installing NPM packages
I am trying to npm install vue-mapbox mapbox-gl, and I'm getting a dependency tree error.我正在尝试 npm 安装 vue-mapbox mapbox-gl,但出现依赖关系树错误。
I'm running Nuxt.js SSR with Vuetify and haven't installed anything related to Mapbox prior to running this install and am getting this error.我正在使用 Vuetify 运行Nuxt.js SSR,并且在运行此安装之前没有安装任何与 Mapbox 相关的东西,并且收到此错误。
38 error code ERESOLVE
39 error ERESOLVE unable to resolve dependency tree
40 error
41 error While resolving: [1mexample[22m@[1m1.0.0[22m
41 error Found: [1mmapbox-gl[22m@[1m1.13.0[22m[2m[22m
41 error [2mnode_modules/mapbox-gl[22m
41 error [1mmapbox-gl[22m@"[1m^1.13.0[22m" from the root project
41 error
41 error Could not resolve dependency:
41 error [35mpeer[39m [1mmapbox-gl[22m@"[1m^0.53.0[22m" from [1mvue-mapbox[22m@[1m0.4.1[22m[2m[22m
41 error [2mnode_modules/vue-mapbox[22m
41 error [1mvue-mapbox[22m@"[1m*[22m" from the root project
41 error
41 error Fix the upstream dependency conflict, or retry
41 error this command with --force, or --legacy-peer-deps
41 error to accept an incorrect (and potentially broken) dependency resolution.
41 error
41 error See /Users/user/.npm/eresolve-report.txt for a full report.
42 verbose exit 1
What's the right way to go about fixing this upstream dependency conflict? go 关于解决这个上游依赖冲突的正确方法是什么?
Looks like it's a problem with Peer Dependencies in the latest version of npm (v7) which is still a beta version.看起来这是最新版本的 npm (v7) 中的 Peer Dependencies 的问题,该版本仍然是 beta 版本。 try with
npm install --legacy-peer-deps
for detail info check this https://blog.npmjs.org/post/626173315965468672/npm-v7-series-beta-release-and-semver-major尝试使用
npm install --legacy-peer-deps
了解详细信息检查此https://blog.npmjs.org/post/626173315965468672/npm-v7-series-beta-release-and-semver-major
Use --legacy-peer-deps
after npm install
.在
npm install
之后使用--legacy-peer-deps
。 For example, if you want to install radium, use:例如,如果要安装镭,请使用:
npm install --legacy-peer-deps --save radium
There are TWO ways:有两种方式:
use npm install --legacy-peer-deps
to install, and if this doesn't work use使用
npm install --legacy-peer-deps
安装,如果这不起作用,请使用
force method.力法。 add --force next to npm install:
npm install --force
在 npm install 旁边添加 --force:
npm install --force
直到 npm 版本 7.19.1 仍然存在相同的问题,升级到版本 7.20.3后使用命令npm install -g npm@latest
和npm audit fix
所有 pkgs 修复没有错误。
You can follow this command你可以按照这个命令
first type:第一种:
npm config set legacy-peer-deps true
then type:然后输入:
npx create-react-app my-app
To Solve Fix the upstream dependency conflict installing NPM packages Error解决 修复安装 NPM 包的上游依赖冲突错误
Method 1. Just Use --legacy-peer-deps after npm install.方法 1.在 npm install 之后使用 --legacy-peer-deps。
For example, if you want to install axios, use例如,如果要安装 axios,请使用
npm install --legacy-peer-deps --save axios.
Method 2. Updating npm and audit fix方法 2.更新 npm 和审计修复
npm I -g npm@latest
npm audit fix --force
Method 3. using --force to install packages方法 3.使用 --force 安装包
npm install axios --force
I tried multiple ways but nothing was working for me.我尝试了多种方法,但没有什么对我有用。 At last tried this and it worked
npm config set legacy-peer-deps true
Run this in the project folder and then try to install any package.最后尝试了这个并且它工作了
npm config set legacy-peer-deps true
在项目文件夹中运行这个然后尝试安装任何包。 Might work for you as well也可能对你有用
要解决 npm 依赖项和与 npm 包的冲突,请使用 npm-check-updates https://www.npmjs.com/package/npm-check-updates
What is happening is that your dependency mexample
requires mmapbox-gl
v1.13.0 and mvue-mapbox
requires v0.53.0.发生的事情是您的依赖
mexample
需要mmapbox-gl
v1.13.0 而mvue-mapbox
需要 v0.53.0。
NPM don't really know what to do, so it gives a warning. NPM 真的不知道该怎么做,所以它会发出警告。 You can bypass the errors using
-- force
or --legacy-peer-deps
but you are ignoring an error.您可以使用
-- force
或--legacy-peer-deps
绕过错误,但您忽略了错误。
Production Options:生产选项:
Probably one of your packages is outdated.可能您的其中一个软件包已过时。 Upgrading packages and fixing upgrade errors might fix the dependency conflict.
升级包和修复升级错误可能会修复依赖冲突。
Overriding a dependency manually to avoid the warning and error.手动覆盖依赖项以避免警告和错误。 What you are doing is setting the version to a specific one that you know that works.
您正在做的是将版本设置为您知道有效的特定版本。 Usually the newer version.
通常是较新的版本。
Example solution with override.具有覆盖的示例解决方案。 Your package.json will look like that:
您的 package.json 将如下所示:
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"mexample": "^1.2.0",
"vue-mapbox": "*"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"overrides": {
"mmapbox-gl": "1.13.0"
}
}
The last option is bypassing using either:最后一个选项是使用以下任一方法绕过:
--legacy-peer-deps
Ignores completely all peerDependencies using the newest version without pinning on package-lock.json --legacy-peer-deps
使用最新版本完全忽略所有peerDependencies而不固定在 package-lock.json--force
Forces the use of the newest pinning all the versions on package-lock.json --force
强制使用最新的固定 package-lock.json 上的所有版本Extra: You shouldn't use "*" as a version because might update major and break dependencies.额外:您不应该使用“*”作为版本,因为可能会更新主要和破坏依赖关系。
使用 npm install --legacy-peer-deps
我已将我的节点版本降级为10.23.1
,它运行良好。
A lot of upvotes for using --legacy-peer-deps
but if --force
works I would recommend using that since it still pins many dependency versions while --legacy-peer-deps
ignore peer dependencies entirely.很多人赞成使用
--legacy-peer-deps
但如果--force
有效,我建议使用它,因为它仍然固定许多依赖版本,而--legacy-peer-deps
完全忽略对等依赖项。 See example below:请参见下面的示例:
https://stackoverflow.com/a/66608842/3850405 https://stackoverflow.com/a/66608842/3850405
Started getting this error on Azure DevOps a few days ago.几天前开始在 Azure DevOps 上收到此错误。 Initially thought it was a glitch on Azure side but since it continued we started looking into it a bit more.
最初认为这是 Azure 方面的一个小故障,但由于它继续存在,我们开始对其进行更多调查。
Turns out the agent we are using, windows-2022
, was updated a few days ago.原来我们使用的代理
windows-2022
是几天前更新的。
https://github.com/actions/virtual-environments/commit/2950cbfeab88a6a6202fa31d7371e574dbe2dc51 https://github.com/actions/virtual-environments/commit/2950cbfeab88a6a6202fa31d7371e574dbe2dc51
Node and NPM now match the Latest Node.js LTS Version: 16.15.1 (includes npm 8.11.0) Node 和 NPM 现在匹配最新的 Node.js LTS 版本:16.15.1(包括 npm 8.11.0)
https://nodejs.org/en/download/ https://nodejs.org/en/download/
You can view all agents included Software here:您可以在此处查看所有代理软件:
https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml#software https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml#software
After reading on Microsoft Visual Studio Developer Community they recommend downgrading Node.js using Node.js Tool Installer task
like this:在阅读 Microsoft Visual Studio 开发人员社区后,他们建议使用
Node.js Tool Installer task
降级 Node.js,如下所示:
- task: NodeTool@0
inputs:
versionSpec: '16.14.2'
https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/node-js?view=azure-devops https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/node-js?view=azure-devops
https://developercommunity.visualstudio.com/t/npm-install-fails-in-azure-devops-hosted-agent/1606509 https://developercommunity.visualstudio.com/t/npm-install-fails-in-azure-devops-hosted-agent/1606509
However we decided that we do not want to downgrade Node.js so first step was matching Node.js locally with LTS Version: 16.15.1 and npm 8.11.0.但是我们决定不想降级 Node.js,所以第一步是在本地匹配 Node.js 与 LTS 版本:16.15.1 和 npm 8.11.0。
When running npm ci
we then got the same error locally.在运行
npm ci
时,我们在本地遇到了同样的错误。
Tried npm ci --force
and we then got this error:尝试了
npm ci --force
,然后我们得到了这个错误:
npm ci
can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync.npm ci
只能在您的 package.json 和 package-lock.json 或 npm-shrinkwrap.json 同步时安装包。 Please update your lock file withnpm install
before continuing.请在继续之前使用
npm install
更新您的锁定文件。
npm install
gave the same error even after node_modules
was manually removed but npm install --force
worked and it generated a new package-lock.json
.即使在手动删除
node_modules
但npm install
npm install --force
工作并生成了新的package-lock.json
之后, npm install 也会出现相同的错误。
npm ci
still failed with the same error but running npm ci --force
worked. npm ci
仍然失败并出现同样的错误,但运行npm ci --force
有效。 We decided to update Azure DevOps .yml
to include --force
and checked in the new package-lock.json
.我们决定更新 Azure DevOps
.yml
以包含--force
并签入新的package-lock.json
。 After doing this everything works like before and we can now update our packages one by one.完成此操作后,一切都像以前一样工作,我们现在可以一个一个地更新我们的包。
I resolved this by adding我通过添加解决了这个问题
steps: - task: NodeTool@0 inputs: versionSpec: '12.x'
I was stuck on this issue for long which also makes error from other commands which calls for some install commands that was breaking.我长期被困在这个问题上,这也会导致其他命令出错,这些命令需要一些破坏性的安装命令。
The only solution that works (maybe suppresses the error) is唯一有效的解决方案(可能会抑制错误)是
npm config set legacy-peer-deps true
This will set the configuration of legacy-peer-deps
to true
这会将
legacy-peer-deps
的配置设置为true
this works for sure这肯定有效
npm config set legacy-peer-deps true npm 配置设置 legacy-peer-deps true
run it then install anything with npm运行它然后用 npm 安装任何东西
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.