首页 > 解决方案 > Npm install 强制在升级到 Angular 7 后自己安装对等依赖项

问题描述

我最近将我的 Angular 应用程序从 6 升级到了 7。当我执行 npm install 时,angular cli 建议您自己安装对等依赖项。当我尝试通过以下命令安装对等依赖项时,例如:

npm install @angular/common@^7.0.0

它在依赖项部分添加了一个条目。所以当我一一安装时,会在依赖项下添加相应包的条目。所以最后我在两个地方得到了相同的包条目。那有意义吗。我做错什么了吗。我的理解是,对等依赖项仅在发布包时使用,所以我可以忽略警告是对的还是我需要安装所有对等依赖项

原始包.json:

{
  "name": "@wtw/toolkit",
  "version": "44.0.5",
  "license": "MIT",
  "dependencies": {
    "@angular/cli": "^7.0.4",
    "deep-diff": "1.0.2",
    "moment": "^2.22.2",
    "ng-click-outside": "^4.0.0"
  },
  "peerDependencies": {
    "@angular/common": "^7.0.0",
    "@angular/compiler": "^7.0.0",
    "@angular/core": "^7.0.0",
    "@angular/forms": "^7.0.0",
    "@angular/http": "^7.0.0",
    "@angular/platform-browser": "^7.0.0",
    "@angular/platform-browser-dynamic": "^7.0.0",
    "@angular/router": "^7.0.0",
    "core-js": "^2.5.7",
    "rxjs": "^6.3.3",
    "zone.js": "^0.8.26"
  }
}

运行 npm install 后,我收到以下警告消息:

npm WARN @wtw/toolkit@44.0.5 requires a peer of @angular/common@^7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @wtw/toolkit@44.0.5 requires a peer of @angular/compiler@^7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @wtw/toolkit@44.0.5 requires a peer of @angular/core@^7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @wtw/toolkit@44.0.5 requires a peer of @angular/forms@^7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @wtw/toolkit@44.0.5 requires a peer of @angular/http@^7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @wtw/toolkit@44.0.5 requires a peer of @angular/platform-browser@^7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @wtw/toolkit@44.0.5 requires a peer of @angular/platform-browser-dynamic@^7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @wtw/toolkit@44.0.5 requires a peer of @angular/router@^7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN @wtw/toolkit@44.0.5 requires a peer of core-js@^2.5.7 but none is installed. You must install peer dependencies yourself.
npm WARN @wtw/toolkit@44.0.5 requires a peer of zone.js@^0.8.26 but none is installed. You must install peer dependencies yourself.
npm WARN ng-click-outside@4.0.0 requires a peer of @angular/common@>=6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ng-click-outside@4.0.0 requires a peer of @angular/core@>=6.0.0 but none is installed. You must install peer dependencies yourself.

我的新 package.json 想要

{
  "name": "@wtw/platform",
  "version": "44.0.15",
  "license": "MIT",
  "dependencies": {
    "@angular/core": "^7.0.1",
    "@ngx-translate/core": "^11.0.0",
    "@ngx-translate/http-loader": "4.0.0",
    "@types/google.analytics": "0.0.39",
    "@wtw/toolkit": "44.0.5",
    "bootstrap": "4.1.3",
    "jsoneditor": "^5.24.7",
    "ng2-file-upload": "^1.3.0",
    "ngx-bootstrap": "3.0.1",
    "ngx-cookie-service": "^1.0.10",
    "ngx-jsoneditor": "^0.1.1",
    "ngx-perfect-scrollbar": "6.3.1"
  },
  "peerDependencies": {
    "@angular/core": "^7.0.1",
    "jquery": "^3.3.1",
    "@angular/animations": "^7.0.1",
    "popper.js": "^1.14.3",
    "@angular/compiler": "^7.0.1",
    "@angular/common": "^7.0.1",
    "@angular/forms": "^7.0.1",
    "@angular/http": "^7.0.1",
    "@angular/platform-browser": "^7.0.1",
    "@angular/platform-browser-dynamic": "^7.0.1",
    "@angular/router": "^7.0.1",
    "core-js": "^2.5.7",
    "rxjs": "^6.3.3",
    "zone.js": "^0.8.26"
  }
}

标签: angularangular7

解决方案


推荐阅读