简体   繁体   中英

npm dependency error when creating a new Angular project

Today i decided to get into Frameworks and picked Angular as a start. I am using Node and npm, which i havent worked with before. I am not a noob at programming itself, but this is rather new to me.

Now when i try to create a new Angular Project called "banking-app", i get the following output in node:

ng new banking-app
? Do you want to enforce stricter type checking and stricter bundle budgets in the workspace?
  This setting helps improve maintainability and catch bugs ahead of time.
  For more information, see https://angular.io/strict No
? Would you like to add Angular routing? No
? Which stylesheet format would you like to use? CSS
CREATE banking-app/angular.json (3575 bytes)
CREATE banking-app/package.json (1201 bytes)
CREATE banking-app/README.md (1019 bytes)
CREATE banking-app/tsconfig.json (538 bytes)
CREATE banking-app/tslint.json (3185 bytes)
CREATE banking-app/.editorconfig (274 bytes)
CREATE banking-app/.gitignore (631 bytes)
CREATE banking-app/.browserslistrc (703 bytes)
CREATE banking-app/karma.conf.js (1428 bytes)
CREATE banking-app/tsconfig.app.json (287 bytes)
CREATE banking-app/tsconfig.spec.json (333 bytes)
CREATE banking-app/src/favicon.ico (948 bytes)
CREATE banking-app/src/index.html (296 bytes)
CREATE banking-app/src/main.ts (372 bytes)
CREATE banking-app/src/polyfills.ts (2830 bytes)
CREATE banking-app/src/styles.css (80 bytes)
CREATE banking-app/src/test.ts (753 bytes)
CREATE banking-app/src/assets/.gitkeep (0 bytes)
CREATE banking-app/src/environments/environment.prod.ts (51 bytes)
CREATE banking-app/src/environments/environment.ts (662 bytes)
CREATE banking-app/src/app/app.module.ts (314 bytes)
CREATE banking-app/src/app/app.component.html (25725 bytes)
CREATE banking-app/src/app/app.component.spec.ts (955 bytes)
CREATE banking-app/src/app/app.component.ts (215 bytes)
CREATE banking-app/src/app/app.component.css (0 bytes)
CREATE banking-app/e2e/protractor.conf.js (904 bytes)
CREATE banking-app/e2e/tsconfig.json (274 bytes)
CREATE banking-app/e2e/src/app.e2e-spec.ts (662 bytes)
CREATE banking-app/e2e/src/app.po.ts (274 bytes)
- Installing packages (npm)...npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: banking-app@0.0.0
npm ERR! Found: typescript@4.1.3
npm ERR! node_modules/typescript
npm ERR!   dev typescript@"~4.1.2" from the root project
npm ERR!   peer typescript@"~4.0.0 || ~4.1.0" from @angular-devkit/build-angular@0.1101.2
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"~0.1101.2" from the root project
npm ERR!   2 more (@angular/compiler-cli, ng-packagr)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer typescript@"~3.9.5" from tsickle@0.39.1
npm ERR! node_modules/tsickle
npm ERR!   peerOptional tsickle@"~0.39.0" from ng-packagr@11.1.3
npm ERR!   node_modules/ng-packagr
npm ERR!     peerOptional ng-packagr@"^11.0.0 || ^11.1.0-next" from @angular-devkit/build-angular@0.1101.2
npm ERR!     node_modules/@angular-devkit/build-angular
npm ERR!       dev @angular-devkit/build-angular@"~0.1101.2" 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! See C:\Users\xyz\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\xyz\AppData\Local\npm-cache\_logs\2021-02-03T14_27_21_486Z-debug.log
× Package install failed, see above.
The Schematic workflow failed. See above.

I have a general understanding what a dependency error is, but zero idea how to manage this in this context. I am rather fresh to node, npm, etc, so I could really use some help getting started with this:|

Thanks in advance!

This error is appear with 7 version of npm (development release). Try to use last LTS version of npm, now it is v6.14.11. To install it run a command in terminal npm i npm@v6.14.11 -g

So I had this same exact problem and I tried what @Miruk had said (which was to update your angular cli) and that did not work. So if this happens to you and updating doesn't work try running:

npm set config legacy-peer-deps true

This ended up working for me. Best of luck!

I also had this issue, resolved by installing the lts version of node, rather than the latest. I think some dependencies have not been updated to work with the latest version.

I had the same error with my new angular project and this solved it:

I upgraded my Node js from v.12 to v.14 and then npm install npm@latest -g .

Also if you are using angular, try doing ng new <name> --skip-install and then do npm i inside the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM