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. 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.
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:
"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?
The most common reason for this is a broken npm install. Please make sure your package. json contains both @angular/compiler-cli and typescript in devDependencies, then delete node_modules and package-lock. json (if you have one) and run npm install again.
Steps To update Angular CLI version globally in your system. First uninstall the existing Angular cli packages. Then run npm cache verify command to clear the node packages cache. Then install latest Angular CLI version using npm install -g @angular/cli@latest command.
To solve the error "Could not find module '@angular-devkit/build-angular'", make sure to install the package by opening your terminal in your project's root directory and running the following command: npm i -D @angular-devkit/build-angular and restart your IDE and development server.
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. This is the same as the accepted answer.
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! See /root/.npm/eresolve-report.txt for a full report. npm ERR!
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. If above approach does not work try removing the node_modules folder and package-lock.json file and run command npm install.
Maybe there were some peer dependencies described that caused the error. Remove node_modules and install it again. Also make sure package.json has no duplicated dependencies. It will override all the dependencies in package.lock.json & package.json file of your project.
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
.
If above approach does not work try removing the node_modules
folder and package-lock.json
file and run command npm install
.
Sound like a problem with Peer Dependencies try with npm install --legacy-peer-deps
.
Per the npm CLI config docs:
Use of
legacy-peer-deps
is not recommended, as it will not enforce thepeerDependencies
contract that meta-dependencies may rely on.
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).
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).
Deleting node_modules was also not necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With