当尝试使用npm i命令安装npm包时,我得到了以下异常:
我尝试重新安装Node.js包,并使用以下方法将代理设置为关闭:
set HTTP_PROXY=
set HTTPS_PROXY=
问题仍然存在。我哪里做错了?
更新:
执行以下命令时:
npm install --legacy-peer-deps
系统显示如下错误:
当尝试使用npm i命令安装npm包时,我得到了以下异常:
我尝试重新安装Node.js包,并使用以下方法将代理设置为关闭:
set HTTP_PROXY=
set HTTPS_PROXY=
问题仍然存在。我哪里做错了?
更新:
执行以下命令时:
npm install --legacy-peer-deps
系统显示如下错误:
当前回答
在我的例子中,我从版本6升级到版本7后开始得到错误(如下所示)。
npm犯错!ERR!无法解析依赖项 树 ... npm犯错!修复上游依赖项冲突,或使用——force或——legacy-peer-deps重试此命令,以接受错误的(可能损坏的)依赖项解决方案。
在我的例子中,使用——legacy-peer-deps或——force标志进行编译会导致一个无用的包。
所以我试着删除node_modules, package-lock。Json和bundle使用yarn install。这就产生了纱线。锁定文件和创建的包锁。Json,在后续的NPM运行中工作良好。
附注:我正在使用临时的解决方法,直到npm 7对我的项目起作用:在那之后,我将删除yarn。锁,package-lock。Json和node_modules文件夹,然后用NPM重新编译
rm -rf node_modules
rm package-lock.json
yarn install
# Generates a yarn.lock file and a new package-lock.json
# Continue with npm
npm start
其他回答
问题似乎是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兼容。
重置package-lock。Json一直都很适合我:
git checkout -- package-lock.json
细节: 在更新遗留项目的所有包时,我经常遇到这种情况——我强烈不建议使用npm审计fix或npm I——force。删除包锁。Json也并不总是适用于我。回滚到包的工作版本。Json +包锁。Json和添加包对我来说是最安全、最快的变体。
最快的解决方案:npm install——legacy-peer-deps
解释:
在npm版本3到6中,peerDependencies不会自动安装,如果在树中发现无效的peer dependency版本,将会发出警告。从npm v7开始,默认安装了peerDependencies。 npm docs: peerDependencies
你的依赖包含一些peerDependencies,这些peerDependencies与根项目的依赖冲突。
正如npm ERR日志中描述的那样。
Yarn有一个特性可以解决这个问题。如果可以,尝试使用它来安装包。
首先要了解问题。以下是我的错误:
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 9.1.0或10.0.0。最上面的消息说,角的公共发现实际上是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
So what should be the solution then? The problem is about peer dependencies. The solution is to downgrade angular common or the solution is to use legacy dependencies logic for installing packages using --legacy-peer-deps. So --legacy-peer-deps does not try to install the peerDependencies automatically. Is this going to work for you? Probably, yes. But you should add specific instructions how to do that, or to make the use of --legacy-peer-deps automatic for future installation of the project packages with this code from one of the previous answers:
npm config set legacy-peer-deps true
In my case I installed the package and I tried to run ng serve, but because --legacy-peer-deps was used, there were dependency packages which were not installed. I had to install those manually (because I did not set the configuration from the code above). At the end installing about five packages manually, all with --legacy-peer-deps, I ended to a package that could not be installed and I did not try to continue, because my project was throwing warnings like crazy and there were a lot of packages for audit too. So my decision was not to use this package and to find an alternative.
我读到的其他解决方案:
downgrade Node.js to v14. This will downgrade npm. It might not be v14, but this was the version that was most widely downgraded to. Some people use Yarn to force package installation - personally I don't understand how this works, because I haven't used Yarn. downgrading Angular and the global Angular CLI version to version that will satisfy the requirement. In my case it is angular/common, and in the question it's angular/core, but both require downgrading the whole angular right (I am not sure about this here). the package you install might have a higher version that doesn't require downgrading Angular. You might try to use the https://updatepackagejson.com/ to upgrade your packages to the latest, but this is in case your project is quite new.