[英]Could not resolve dependency: npm ERR! peer @angular/compiler@"11.2.8"
I am trying to get my app to deploy on Heroku. I was getting the "sh: 1: ng: not found" error but based on responses on here, I moved my @angular/cli, @angular-devkit/build-angular, @angular/compiler-cli, and typescript. Now I am getting a "Could not resolve dependency: npm ERR. peer @angular/compiler@"11.2.8"" error?我正在尝试让我的应用程序在 Heroku 上部署。我收到“sh: 1: ng: not found”错误,但根据此处的回复,我移动了我的@angular/cli、@angular-devkit/build-angular 、@angular/compiler-cli 和 typescript。现在我收到“无法解析依赖项:npm ERR.peer @angular/compiler@"11.2.8"”错误? I think it is having a versioning issue.
我认为它存在版本控制问题。 I'm not sure what is going on.
我不确定发生了什么。
I've tried running 'npm update' and tried manually inserting the '@angular/compiler@"11.2.8"' to dependencies and then running 'npm i' but both give me this same error.我试过运行“npm update”并尝试手动将“@angular/compiler@"11.2.8"”插入依赖项,然后运行“npm i”,但两者都给我同样的错误。
Here is my error:这是我的错误:
npm ERR! Found: @angular/compiler@11.0.9
npm ERR! node_modules/@angular/compiler
npm ERR! @angular/compiler@"~11.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/compiler@"11.2.8" from @angular/compiler-cli@11.2.8
npm ERR! node_modules/@angular/compiler-cli
npm ERR! dev @angular/compiler-cli@"^11.0.9" from the root project
npm ERR! peer @angular/compiler-cli@"^11.0.0" from @angular-devkit/build-angular@0.1100.7
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! @angular-devkit/build-angular@"~0.1100.2" from the root project
Package.json: Package.json:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"postinstall": "ngcc"
},
"private": true,
"dependencies": {
"@angular-devkit/build-angular": "~0.1100.2",
"@angular/animations": "~11.0.1",
"@angular/cdk": "^11.2.6",
"@angular/cli": "~11.0.2",
"@angular/common": "~11.0.1",
"@angular/compiler": "~11.0.1",
"@angular/core": "~11.0.1",
"@angular/flex-layout": "^11.0.0-beta.33",
"@angular/forms": "~11.0.1",
"@angular/material": "^11.2.6",
"@angular/platform-browser": "~11.0.1",
"@angular/platform-browser-dynamic": "~11.0.1",
"@angular/router": "~11.0.1",
"angular-in-memory-web-api": "^0.11.0",
"rxjs": "~6.6.0",
"tslib": "^2.0.0",
"typescript": "~4.0.2",
"uuid": "^3.4.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.1100.2",
"@angular/cli": "~11.0.2",
"@angular/compiler-cli": "^11.0.9",
"@types/jasmine": "~3.6.0",
"@types/node": "^12.11.1",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage": "~2.0.3",
"karma-jasmine": "~4.0.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~4.0.2"
}
How does one resolve this error?如何解决这一错误?
In addition to using the npm install --save --legacy-peer-deps
command line option, this can also be set more permanently as a config option: npm config set legacy-peer-deps true
.除了使用
npm install --save --legacy-peer-deps
命令行选项之外,还可以将其设置为更永久的配置选项: npm config set legacy-peer-deps true
。
If above approach does not work try removing the node_modules
folder and package-lock.json
file and run command npm install
.如果上述方法不起作用,请尝试删除
node_modules
文件夹和package-lock.json
文件并运行命令npm install
。
Sound like a problem with Peer Dependencies try with npm install --legacy-peer-deps
.听起来像是对等依赖项的问题,尝试使用
npm install --legacy-peer-deps
。
Perthe npm CLI config docs :根据npm CLI 配置文档:
Use of
legacy-peer-deps
is not recommended, as it will not enforce thepeerDependencies
contract that meta-dependencies may rely on.不推荐使用
legacy-peer-deps
,因为它不会强制执行元依赖可能依赖的peerDependencies
合约。
In an attempt to try to follow npm's recommendations, instead of setting --legacy-peer-deps
I checked the package-lock.json and noticed that the devDependencies (for Angular-related packages) were still referencing the older version (in my case 13.0.1, upgrading to 13.2.0).为了尝试遵循 npm 的建议,我没有设置
--legacy-peer-deps
,而是检查了 package-lock.json 并注意到 devDependencies(对于 Angular 相关的包)仍在引用旧版本(在我的情况下) 13.0.1,升级到 13.2.0)。
I simply deleted the package-lock.json and ran npm install
and it installed the updates that ng update @angular/cli @angular/core
had made (to package.json).我只是删除了 package-lock.json 并运行
npm install
并安装了ng update @angular/cli @angular/core
所做的更新(到 package.json)。
Deleting node_modules was also not necessary.也没有必要删除 node_modules。
You may be using a newer version of node.您可能正在使用更新版本的节点。 I got this using node 17. I rolled node back to 14 (the version used in the project originally) and npm installed fine.
我使用节点 17 得到了这个。我将节点回滚到 14(项目中最初使用的版本)并且 npm 安装良好。
I recommend using NVM in the future.我建议将来使用NVM 。 You can add a
.nvm
file to you project so you can lock in the node version to use.您可以将
.nvm
文件添加到项目中,以便锁定要使用的节点版本。
I got the issue when installing Angular Material.安装 Angular 材料时出现问题。 Fixed it by removing the @latest from the command.
通过从命令中删除@latest来修复它。
Changed改变了
ng add @angular/material@latest
to到
ng add @angular/material
No more error and installation succeeded.没有更多错误,安装成功。
npm install --save --legacy-peer-deps
worked for me! npm install --save --legacy-peer-deps
为我工作!
My error log was the following:我的错误日志如下:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: angular-tour-of-heroes@0.0.0
npm ERR! Found: rxjs@7.4.0
npm ERR! node_modules/rxjs
npm ERR! rxjs@"~7.4.0" from the root project
npm ERR! peer rxjs@"^6.5.3 || ^7.4.0" from @angular/common@13.0.1
npm ERR! node_modules/@angular/common
npm ERR! @angular/common@"~13.0.0" from the root project
npm ERR! peer @angular/common@">=8.0.0" from angular-in-memory-web-api@0.11.0
npm ERR! node_modules/angular-in-memory-web-api
npm ERR! angular-in-memory-web-api@"*" from the root project
npm ERR! 1 more (@angular/core)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer rxjs@"^6.0.0" from angular-in-memory-web-api@0.11.0
npm ERR! node_modules/angular-in-memory-web-api
npm ERR! angular-in-memory-web-api@"*" from the root project
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.