npm错误,尝试在Angular项目中运行

huangapple go评论69阅读模式
英文:

npm ERROR trying to run a project in Angular

问题

我试图用 ng serve -o 运行我的项目。问题是屏幕上出现了以下警告:

您的全局 Angular CLI 版本(15.2.2)大于您的本地版本(15.0.4)。将使用本地 Angular CLI 版本。

要禁用此警告,请使用“ng config -g cli.warnings.versionMismatch false”命令。

我使用 install -g @angular/cli 重新安装了 Angular,然后使用 npm install --save-dev @angular/cli@latest 升级了我的本地版本,但是当我输入该命令时,出现了以下内容:

C:\Users\user1\Dropbox\Angular\myApp>npm install --save-dev @angular/cli@latest
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: karma-jasmine-html-reporter@1.7.0
npm ERR! Found: jasmine-core@3.6.0
npm ERR! node_modules/jasmine-core
npm ERR!   jasmine-core@“^3.6.0” from karma-jasmine@4.0.2
npm ERR!   node_modules/karma-jasmine
npm ERR!     peer karma-jasmine@“>=1.1” from karma-jasmine-html-reporter@1.7.0
npm ERR!     node_modules/karma-jasmine-html-reporter
npm ERR!       dev karma-jasmine-html-reporter@“^1.5.0” from the root project
npm ERR!     dev karma-jasmine@“~4.0.0” from the root project
npm ERR!   dev jasmine-core@“~3.6.0” from the root project
npm ERR!
npm ERR! Conflicting peer dependency: jasmine-core@4.5.0
npm ERR! node_modules/jasmine-core
npm ERR!   peer jasmine-core@“>=3.8” from karma-jasmine-html-reporter@1.7.0
npm ERR!   node_modules/karma-jasmine-html-reporter
npm ERR!     dev karma-jasmine-html-reporter@“^1.5.0” from the root project
npm ERR!
npm ERR! 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 ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\user1\AppData\Local\npm-cache\_logs23-03-09T17_09_29_793Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user1\AppData\Local\npm-cache\_logs23-03-09T17_09_29_793Z-debug-0.log

我不知道该怎么办,请问我该如何解决这个问题?

英文:

I'm triying to run my project with ng serve -o. The problem is that the following warning appears on the screen:

Your global Angular CLI version (15.2.2) is greater than your local version (15.0.4). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".

I reinstalled angular with install -g @angular/cli and then use npm install --save-dev @angular/cli@latest for upgrade my local version but, when I enter the command the following appears:

C:\Users\user1\Dropbox\Angular\myApp>npm install --save-dev @angular/cli@latest
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: karma-jasmine-html-reporter@1.7.0
npm ERR! Found: jasmine-core@3.6.0
npm ERR! node_modules/jasmine-core
npm ERR!   jasmine-core@"^3.6.0" from karma-jasmine@4.0.2
npm ERR!   node_modules/karma-jasmine
npm ERR!     peer karma-jasmine@">=1.1" from karma-jasmine-html-reporter@1.7.0
npm ERR!     node_modules/karma-jasmine-html-reporter
npm ERR!       dev karma-jasmine-html-reporter@"^1.5.0" from the root project
npm ERR!     dev karma-jasmine@"~4.0.0" from the root project
npm ERR!   dev jasmine-core@"~3.6.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: jasmine-core@4.5.0
npm ERR! node_modules/jasmine-core
npm ERR!   peer jasmine-core@">=3.8" from karma-jasmine-html-reporter@1.7.0
npm ERR!   node_modules/karma-jasmine-html-reporter
npm ERR!     dev karma-jasmine-html-reporter@"^1.5.0" from the root project
npm ERR!
npm ERR! 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 ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\user1\AppData\Local\npm-cache\_logs23-03-09T17_09_29_793Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user1\AppData\Local\npm-cache\_logs23-03-09T17_09_29_793Z-debug-0.log

I don't know what I can do, so please how I can resolve this problem?

答案1

得分: 1

答案就在错误信息中:

npm ERR! 修复上游依赖冲突,或使用 --force 或 --legacy-peer-deps 选项重试此命令
npm ERR! 以接受错误的(可能是破损的)依赖解决方案。

当你运行 npm i 时,由于对等依赖版本不匹配,你需要指定 --force--legacy-peer-deps,或者你需要在项目根目录创建一个 .npmrc 文件,并添加:

legacy-peer-deps=true

一旦你的版本不匹配的依赖问题解决了,你就不会再遇到这个错误。

英文:

The answer is in the error itself:

npm ERR! 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.

When you run npm i, you need to specify --force or --legacy-peer-deps due to peer dependency version mismatches, or you need to create an .npmrc file in your project root with:

legacy-peer-deps=true

Once your version mismatches with dependencies are resolved, you won't get this error.

huangapple
  • 本文由 发表于 2023年3月10日 01:32:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75688128.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定