代码之家  ›  专栏  ›  技术社区  ›  Puschie

在删除node_modules之前,npm无法解析依赖树

  •  0
  • Puschie  · 技术社区  · 1 年前

    试着理解npm的错误报告,但没有找到问题-令人惊讶的是,删除node_modules目录修复了它。我们正在将angular更新为18+,将nx更新为19+。

    Found: @angular-devkit/[email protected]
    node_modules/@angular-devkit/build-angular
      dev @angular-devkit/build-angular@"18.0.4" from the root project
      peer @angular-devkit/build-angular@">= 15.0.0 < 18.0.0" from @nx/[email protected]
      node_modules/@nx/angular
        @nx/angular@"19.3.0" from the root project
        @nx/angular@"18.3.4" from @nrwl/[email protected]
        node_modules/@nrwl/angular
          @nrwl/angular@"18.3.4" from @nx/[email protected]
      peer @angular-devkit/build-angular@">=15.0.0 <18.0.0" from [email protected]
      node_modules/jest-preset-angular
        dev jest-preset-angular@"14.1.1" from the root project
    
    Could not resolve dependency:
    dev @angular-devkit/build-angular@"18.0.4" from the root project
    
    Conflicting peer dependency: @angular/[email protected]
    node_modules/@angular/compiler-cli
      peer @angular/compiler-cli@"^18.0.0" from @angular-devkit/[email protected]
      node_modules/@angular-devkit/build-angular
        dev @angular-devkit/build-angular@"18.0.4" from the root project
    

    我如何理解最后一部分:

    1. @角度devkit/ [email protected] 在package.json中找到
    2. 包与@angular/compiler cli@^18.0.0具有对等依赖关系
    3. 未能解析@angular/ [email protected] (也在package.json中)

    为什么它无法解决@angular问题/ [email protected] 什么时候它显然是一个有效的版本?

    我如何理解第一部分:

    1. [email protected] 在package.json中找到
    2. 该包的14.0.3版本具有对@angular devkit/build-angular@>=15.0.0<18.0.0
    3. (解决基于错误版本范围的错误)

    为什么npm使用旧版本的jest预设角度和nx/角度进行解析?它似乎忽略了package.json中指定的版本,并使用当前安装的版本。

    (删除nod_modules来修复npm依赖性问题对我来说就像是npm本身的一个bug)

    package.json

    "dependencies": {
        "@abp/ng.components": "8.1.3",
        "@abp/ng.core": "8.1.3",
        "@abp/ng.oauth": "8.1.3",
        "@abp/ng.theme.shared": "8.1.3",
        "@angular/animations": "18.0.3",
        "@angular/common": "18.0.3",
        "@angular/compiler": "18.0.3",
        "@angular/core": "18.0.3",
        "@angular/forms": "18.0.3",
        "@angular/localize": "18.0.3",
        "@angular/platform-browser": "18.0.3",
        "@angular/platform-browser-dynamic": "18.0.3",
        "@angular/router": "18.0.3",
        "@ngrx/effects": "18.0.0",
        "@ngrx/store": "18.0.0",
        "@ngrx/operators": "18.0.0",
        "@nx/angular": "19.3.0",
        "@puschie286/golden-layout": "^2.6.2",
        "@types/lodash-es": "^4.17.12",
        "angular-oauth2-oidc": "^17.0.2",
        "bootstrap-icons": "^1.11.3",
        "lodash-es": "^4.17.21",
        "primeicons": "^7.0.0",
        "primeng": "^17.18.1",
        "primeng-locale": "github:primefaces/primelocale",
        "primeng-sass-theme": "github:primefaces/primeng-sass-theme",
        "rxjs": "~7.8.1",
        "ts-debounce": "^4.0.0",
        "tslib": "^2.6.2",
        "zone.js": "0.14.4"
      },
      "devDependencies": {
        "@abp/ng.schematics": "^8.1.3",
        "@abp/nx.generators": "^8.1.3",
        "@angular-devkit/build-angular": "18.0.4",
        "@angular-devkit/core": "18.0.4",
        "@angular-devkit/schematics": "18.0.4",
        "@angular-eslint/eslint-plugin": "18.0.1",
        "@angular-eslint/eslint-plugin-template": "18.0.1",
        "@angular-eslint/template-parser": "18.0.1",
        "@angular/cli": "~18.0.0",
        "@angular/compiler-cli": "18.0.3",
        "@angular/language-service": "18.0.3",
        "@ngrx/eslint-plugin": "18.0.0",
        "@ngrx/schematics": "18.0.0",
        "@ngrx/store-devtools": "18.0.0",
        "@nx-dotnet/core": "^2.2.0",
        "@nx/cypress": "19.3.0",
        "@nx/eslint": "19.3.0",
        "@nx/eslint-plugin": "19.3.0",
        "@nx/jest": "19.3.0",
        "@nx/js": "19.3.0",
        "@nx/plugin": "19.3.0",
        "@nx/web": "19.3.0",
        "@nx/workspace": "19.3.0",
        "@schematics/angular": "18.0.4",
        "@swc-node/register": "1.9.2",
        "@swc/core": "1.5.7",
        "@types/jest": "^29.5.12",
        "@types/node": "^20.11.17",
        "@typescript-eslint/eslint-plugin": "7.3.0",
        "@typescript-eslint/parser": "7.3.0",
        "@typescript-eslint/utils": "^8.0.0-alpha.28",
        "autoprefixer": "^10.4.17",
        "cypress": "13.8.1",
        "daisyui": "^4.6.3",
        "eslint": "8.57.0",
        "eslint-config-prettier": "^9.1.0",
        "eslint-plugin-cypress": "^2.15.1",
        "jasmine-marbles": "~0.9.2",
        "jest": "^29.7.0",
        "jest-environment-jsdom": "^29.7.0",
        "jest-preset-angular": "14.1.1",
        "jsonc-eslint-parser": "^2.4.0",
        "nx": "19.3.0",
        "postcss": "^8.4.38",
        "prettier": "^3.2.5",
        "tailwindcss": "^3.4.3",
        "ts-jest": "^29.1.2",
        "ts-node": "10.9.2",
        "typescript": "5.4.3"
      }
    
    1 回复  |  直到 1 年前
        1
  •  1
  •   adsy    1 年前

    @nx/ [email protected] [email protected] 两者都指定需要 @angular-devkit/build-angular 那就是 >= 15.0.0 < 18.0.0 .

    不幸的是,此范围不包括的任何版本 18.x.x 。与该范围匹配的最新版本为 17.3.8 根据 the NPM semver calculator .

    对于 @nx/angular 看起来这是固定的 https://github.com/nrwl/nx/pull/22509 对于 jest-preset-angular 它被固定在 https://github.com/thymikee/jest-preset-angular/blob/main/CHANGELOG.md#1410-2024-05-21 .

    它使用旧版本,因为您可能有 package-lock.json 其存储来自先前安装的这些依赖关系的可传递版本。这是经过设计和最佳实践的,但在复杂的升级场景中需要一些额外的工作来管理。请参阅 package-lock.json .

    有了最新的NPM,你需要做一些事情,比如 npm update --save @nx/angular jest-preset-angular .

    并确保对 package-lock.json 和(可能,只有当他们是直接deps时,这种情况才会改变) package.json 承诺。如果有人提交了本应导致 package-lock.json 更新,但未包括在内。实际上,这意味着在CI中您使用 npm ci 而且永远不会 npm install .

    当然,永远不要承诺 node_modules .