简体   繁体   English

新建Angular项目时出现npm依赖错误

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

Today i decided to get into Frameworks and picked Angular as a start.今天我决定进入框架并选择 Angular 作为开始。 I am using Node and npm, which i havent worked with before.我正在使用 Node 和 npm,我以前没有使用过。 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:现在,当我尝试创建一个名为“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.

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:|我对节点、npm 等比较陌生,所以我真的可以使用一些帮助来入门:|

Thanks in advance!提前致谢!

This error is appear with 7 version of npm (development release). 7版本的npm(开发版)出现此错误。 Try to use last LTS version of npm, now it is v6.14.11.尝试使用 npm 的最新 LTS 版本,现在是 v6.14.11。 To install it run a command in terminal npm i npm@v6.14.11 -g要安装它,请在终端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.所以我遇到了同样的问题,我尝试了@Miruk 所说的(这是更新你的 angular cli),但没有奏效。 So if this happens to you and updating doesn't work try running:因此,如果您遇到这种情况并且更新不起作用,请尝试运行:

npm set config legacy-peer-deps true npm 设置配置 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.我也有这个问题,通过安装节点的 lts 版本而不是最新版本来解决。 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:我的新 angular 项目遇到了同样的错误,这解决了它:

I upgraded my Node js from v.12 to v.14 and then npm install npm@latest -g .我将我的 Node js 从 v.12 升级到 v.14,然后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.此外,如果您使用 angular,请尝试在项目中执行ng new <name> --skip-install然后执行npm i

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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