我遇到了一个奇怪的问题,GitHub操作工作流突然无法编译Angular 项目,而它仍然可以在我(和我的同事)的本地机器上运行.请注意,我正在运行npm ci,而不是npm install.

这是我遇到的错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @angular-eslint/schematics@13.2.1
npm ERR! Found: @angular/cli@14.0.0
npm ERR! node_modules/@angular/cli
npm ERR!   dev @angular/cli@"^14.0.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/cli@">= 13.0.0 < 14.0.0" from @angular-eslint/schematics@13.2.1
npm ERR! node_modules/@angular-eslint/schematics
npm ERR!   dev @angular-eslint/schematics@"^13.2.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @angular/cli@13.3.7
npm ERR! node_modules/@angular/cli
npm ERR!   peer @angular/cli@">= 13.0.0 < 14.0.0" from @angular-eslint/schematics@13.2.1
npm ERR!   node_modules/@angular-eslint/schematics
npm ERR!     dev @angular-eslint/schematics@"^13.2.1" 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 /home/runner/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2022-06-09T16_17_41_426Z-debug-0.log
Error: Process completed with exit code 1.

这是我的package.json:

{
  "name": "dashboard",
  "version": "0.0.0",
  "scripts": {
    "build": "ng build --source-map=false",
    "start": "ng serve --configuration walabot-home",
    "dev": " ng serve --configuration walabothome-app-cloud"
  },
  "engines": {
    "node": "16"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^14.0.0",
    "@angular/cdk": "^14.0.1",
    "@angular/common": "^14.0.0",
    "@angular/compiler": "^14.0.0",
    "@angular/core": "^14.0.0",
    "@angular/forms": "^14.0.0",
    "@angular/localize": "^14.0.0",
    "@angular/material": "^14.0.1",
    "@angular/platform-browser": "^14.0.0",
    "@angular/platform-browser-dynamic": "^14.0.0",
    "@angular/router": "^14.0.0",
    "@types/hammerjs": "^2.0.41",
    "angular2-csv": "^0.2.9",
    "axios": "^0.27.2",
    "core-js": "^3.22.8",
    "firebase": "^9.8.2",
    "ngx-material-timepicker": "^5.5.3",
    "rxjs": "^7.5.5",
    "tslib": "^2.4.0",
    "zone.js": "^0.11.5"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.0.0",
    "@angular/cli": "^14.0.0",
    "@angular/compiler-cli": "^14.0.0",
    "@angular/language-service": "^14.0.0",
    "@types/jasmine": "^4.0.3",
    "@types/jasminewd2": "^2.0.10",
    "codelyzer": "^6.0.2",
    "esbuild": "^0.14.43",
    "jasmine-core": "^4.1.1",
    "jasmine-spec-reporter": "^7.0.0",
    "karma": "^6.3.20",
    "karma-chrome-launcher": "^3.1.1",
    "karma-coverage-istanbul-reporter": "^3.0.3",
    "karma-jasmine": "^5.0.1",
    "karma-jasmine-html-reporter": "^2.0.0",
    "luxon": "^2.4.0",
    "openapi-typescript-codegen": "^0.23.0",
    "protractor": "^7.0.0",
    "ts-node": "^10.8.1",
    "tslint": "^6.1.0",
    "typescript": "^4.7.3"
  },
  "optionalDependencies": {
    "fsevents": "2.3.2"
  }
}

CI工作流:

name: Dashboard

on:
  workflow_call:
    inputs:
      project-id:
        required: true
        type: string

jobs:
  build:
    runs-on: [ubuntu-latest]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version-file: ".nvmrc"
          cache: "npm"
          cache-dependency-path: package-lock.json
      - run: npm ci
      - run: npm run build -- --configuration=${{ inputs.project-id }}
      - uses: actions/upload-artifact@v3
        with:
          name: dashboard-dist
          path: dashboard/dist

编辑:降级到Angular CLI 13时,仍会出现问题:

npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: angular2-csv@0.2.9
npm ERR! Found: @angular/common@14.0.0
npm ERR! node_modules/@angular/common
npm ERR!   @angular/common@"^14.0.0" from the root project
npm ERR!   peer @angular/common@"^14.0.0 || ^15.0.0" from @angular/cdk@14.0.1
npm ERR!   node_modules/@angular/cdk
npm ERR!     @angular/cdk@"^14.0.1" from the root project
npm ERR!     peer @angular/cdk@"14.0.1" from @angular/material@14.0.1
npm ERR!     node_modules/@angular/material
npm ERR!       @angular/material@"^14.0.1" from the root project
npm ERR!   5 more (@angular/forms, @angular/material, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/common@"^6.0.0-rc.0 || ^6.0.0" from angular2-csv@0.2.9
npm ERR! node_modules/angular2-csv
npm ERR!   angular2-csv@"^0.2.9" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @angular/common@6.1.10
npm ERR! node_modules/@angular/common
npm ERR!   peer @angular/common@"^6.0.0-rc.0 || ^6.0.0" from angular2-csv@0.2.9
npm ERR!   node_modules/angular2-csv
npm ERR!     angular2-csv@"^0.2.9" 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 /home/runner/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2022-06-09T17_31_14_082Z-debug-0.log

推荐答案

正如walid所说,只需降低Angular cli:

devDependencies": {
"@angular/cli": "13.0.0",

也许13号对你有用.

编辑:

Angular相关问答推荐

为什么当我在父组件中设置数组元素时,Angular重新创建子组件而不是更新它?

间歇性不正确的SSR重定向(server. ts级别的请求和响应不匹配)

为什么这个拦截器只在发送事件上触发,而不是在实际响应上触发?

以17角表示的自定义元素

Rxjs重置执行后的可观察延迟并重新调度Angular

如果我只在组件中使用某个主题,是否需要取消订阅该主题?

ngRouterOutlet和组件生命周期使用自定义模板渲染的问题

如何使用指令以Angular 传递默认值

通过 SignalR 事件组件重定向Angular 页面后不起作用

如何在Cypress 测试中切换 Angular 选项卡

如何在Angular Material2中获取活动选项卡

错误:您要查找的资源已被删除、名称已更改或暂时不可用

Angular 2: Debounce(ngModelChange)?

Angular 没有可用于依赖类型的模块工厂:ContextElementDependency

找不到模块'@angular/compiler'

Electron - 不允许加载本地资源

Angular 2 应用程序中没有Access-Control-Allow-Origin标头

使用 DomSanitizer 绕过安全性后,安全值必须使用 [property]=binding

NG 测试中的调试测试

Angular 5 中 value 和 ngValue 的区别