簡體   English   中英

新建Angular項目時出現npm依賴錯誤

[英]npm dependency error when creating a new Angular project

今天我決定進入框架並選擇 Angular 作為開始。 我正在使用 Node 和 npm,我以前沒有使用過。 我不是編程本身的菜鳥,但這對我來說相當新。

現在,當我嘗試創建一個名為“banking-app”的新 Angular 項目時,我在節點中得到以下 output:

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.

我對什么是依賴錯誤有一個大致的了解,但對如何在這種情況下管理它的想法為零。 我對節點、npm 等比較陌生,所以我真的可以使用一些幫助來入門:|

提前致謝!

7版本的npm(開發版)出現此錯誤。 嘗試使用 npm 的最新 LTS 版本,現在是 v6.14.11。 要安裝它,請在終端npm i npm@v6.14.11 -g中運行命令

所以我遇到了同樣的問題,我嘗試了@Miruk 所說的(這是更新你的 angular cli),但沒有奏效。 因此,如果您遇到這種情況並且更新不起作用,請嘗試運行:

npm 設置配置 legacy-peer-deps true

這最終為我工作。 祝你好運!

我也有這個問題,通過安裝節點的 lts 版本而不是最新版本來解決。 我認為某些依賴項尚未更新以適用於最新版本。

我的新 angular 項目遇到了同樣的錯誤,這解決了它:

我將我的 Node js 從 v.12 升級到 v.14,然后npm install npm@latest -g

此外,如果您使用 angular,請嘗試在項目中執行ng new <name> --skip-install然后執行npm i

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM