RUDE

Angular 14 получает ошибку при установке apollo-angular

Два дня назад пытаюсь установить apollo на Angular приложение. но я получаю эту ошибку:

The package apollo-angular@3.0.1 will be installed and executed.
Would you like to proceed? Yes
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: frontend@0.0.0
npm ERR! Found: @angular/core@14.0.6
npm ERR! node_modules/@angular/core
npm ERR!   @angular/core@"^14.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"^12.0.0 || ^13.0.0" from apollo-angular@3.0.1
npm ERR! node_modules/apollo-angular
npm ERR!   apollo-angular@"3.0.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 C:\Users\xxx\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\xxx\AppData\Local\npm-cache\_logs\2022-07-18T14_07_12_565Z-debug-0.log
× Packages installation failed, see above.

Добавление --force или --legacy-peer-deps в конец команды установки не помогло решить мою проблему

Angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "frontend": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/frontend",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "frontend:build:production"
            },
            "development": {
              "browserTarget": "frontend:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "frontend:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css",
              "src/styles.css"
            ],
            "scripts": [
            ]
          }
        }
      }
    }
  },
  "cli": {
    "analytics": false
  }
}

Packages.json:

{
  "name": "frontend",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "json-run": "json-server --watch db.js",
    "gql-server": "json-graphql-server gql.js"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^14.0.0",
    "@angular/cdk": "^14.0.4",
    "@angular/common": "^14.0.0",
    "@angular/compiler": "^14.0.0",
    "@angular/core": "^14.0.0",
    "@angular/forms": "^14.0.0",
    "@angular/material": "^14.0.4",
    "@angular/platform-browser": "^14.0.0",
    "@angular/platform-browser-dynamic": "^14.0.0",
    "@angular/router": "^14.0.0",
    "@ngrx/data": "^14.0.2",
    "@ngrx/effects": "^14.0.2",
    "@ngrx/entity": "^14.0.2",
    "@ngrx/store": "^14.0.2",
    "cors": "^2.8.5",
    "express": "^4.18.1",
    "express-graphql": "^0.12.0",
    "graphql": "^16.5.0",
    "jalali-moment": "^3.3.11",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^14.0.1",
    "@angular/cli": "~14.0.1",
    "@angular/compiler-cli": "^14.0.0",
    "@types/jasmine": "~4.0.0",
    "bootstrap": "~4.3.1",
    "jasmine-core": "~4.1.0",
    "jquery": "^3.6.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.7.2"
  },
  "description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.0.1.",
  "main": "gql.js",
  "keywords": [],
  "author": "",
  "license": "ISC"
}

1
703
2

Ответы:

Решено

От ошибки

npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"^12.0.0 || ^13.0.0" from apollo-angular@3.0.1
npm ERR! node_modules/apollo-angular
npm ERR!   apollo-angular@"3.0.1" from the root project

Похоже, apollo-angular@3.0.1 не поддерживает angular 14. Похоже, есть открытая проблема с поддержкой angular 14 от apollo-angular. Вы можете либо использовать --legacy-peer-deps в качестве флага во время установки (и, возможно, устранить другие нарушения по пути), либо подождать, пока проблема не будет решена, и перейти на angular 13 на данный момент.


Я столкнулся с той же проблемой, и я только что увидел это сообщение здесь от Destreyf с решением, которое работает для меня:

It's not a perfect solution but I've added an "overrides" property in my package.json and it allows me to successfully install apollo-angular with angular 14.
{
  ...
  "dependencies": ...,
  "devDependencies": ...,
  "overrides": {
    "apollo-angular": {
      "@angular/core": "$@angular/core"
    },
  }
}
This requires npm 8.3 or greater to work. It effectively rewrites angular-apollo's @angular/core to use whatever version is in the dependencies field.