【问题标题】:Could not resolve dependency: npm ERR! peer @angular/compiler@"11.2.8"无法解决依赖关系:npm ERR!同行@angular/compiler@"11.2.8"
【发布时间】:2021-07-03 11:04:21
【问题描述】:

我正在尝试让我的应用部署在 Heroku 上。我收到“sh: 1: ng: not found”错误,但根据此处的响应,我移动了我的 @angular/cli、@angular-devkit/build-angular、@angular/compiler-cli 和 typescript。现在我收到“无法解决依赖关系:npm ERR!peer @angular/compiler@"11.2.8"”错误。我认为它有版本问题?我不确定发生了什么。

我尝试运行 'npm update' 并尝试手动将 '@angular/compiler@"11.2.8"' 插入依赖项,然后运行 ​​'npm i' 但都给了我同样的错误。

这是我的错误:

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

包.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"
  }

如何解决这个错误?

【问题讨论】:

    标签: angular-cli angular-compiler


    【解决方案1】:

    除了使用npm install --save --legacy-peer-deps 命令行选项外,还可以将其设置为更永久的配置选项: npm config set legacy-peer-deps true.

    如果上述方法不起作用,请尝试删除node_modules 文件夹和package-lock.json 文件并运行命令npm install

    【讨论】:

    • npm install --save --legacy-peer-deps 命令给了我一个“错误:worker #1 错误:TypeError: compiler_1.devOnlyGuardedExpression is not a function”你知道这是什么意思吗?
    • 我尝试了第二个命令,然后删除了 node_modules/package-lock.json 并且我认为编译器版本控制问题已修复!谢谢!!不幸的是,现在 ng not found 问题又回来了……我会对此进行更多研究
    • 我有一个非常相似的问题,第二种方法对我有用。
    • 谢谢它对我来说很好。
    【解决方案2】:

    听起来像是 Peer Dependencies 的问题,试试 npm install --legacy-peer-deps

    【讨论】:

    • 这给了我一个“错误:worker #1 错误:TypeError: compiler_1.devOnlyGuardedExpression is not a function”错误
    【解决方案3】:

    the npm CLI config docs:

    不推荐使用legacy-peer-deps,因为它不会强制执行元依赖可能依赖的peerDependencies 合约。

    为了尝试遵循 npm 的建议,我没有设置 --legacy-peer-deps,而是检查了 package-lock.json 并注意到 devDependencies(对于 Angular 相关的包)仍在引用旧版本(在我的例子中是 13.0 .1,升级到 13.2.0)。

    我只是删除了 package-lock.json 并运行 npm install 并安装了 ng update @angular/cli @angular/core 所做的更新(到 package.json)。

    也没有必要删除 node_modules。

    【讨论】:

      【解决方案4】:

      npm install --save --legacy-peer-deps 为我工作!

      我的错误日志如下:

      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.
      

      【讨论】:

      猜你喜欢
      • 2022-11-18
      • 2018-01-01
      • 1970-01-01
      • 2016-02-16
      • 2017-02-20
      相关资源
      最近更新 更多