NPM - 解决Package.json中的对等依赖关系

时间:2017-04-27 22:24:14

标签: node.js angular npm dependencies package.json

我想知道我是否正在我的package.json中正确解析未满足的对等依赖项。如果我遇到错误UNMET PEER DEPENDENCY {package@version},我应该将依赖项安装到“依赖项”或“devDependencies”还是依赖它?

我试过了

npm install --save {package}

npm install --save-dev {package}

请注意,我在每次安装后运行以下内容 -

rm -rf ~/.npm
rm -rf node_modules
npm cache clean
npm install  

我的具体问题是在运行npm install之后,我在项目根目录下有以下未满足的对等依赖项。只有@angular core&常见的是另一个包 -

path/to/app
├── UNMET PEER DEPENDENCY @angular/animations@4.1.0
├── UNMET PEER DEPENDENCY @angular/common@4.1.0 invalid
├── UNMET PEER DEPENDENCY @angular/compiler@4.1.0
├── UNMET PEER DEPENDENCY @angular/core@4.1.0 invalid
├── UNMET PEER DEPENDENCY @angular/platform-browser@4.1.0
├── UNMET PEER DEPENDENCY @angular/platform-browser-dynamic@4.0.3
├─┬ @swimlane/ngx-charts-dag@1.0.0
│ ├── UNMET PEER DEPENDENCY @angular/common@~2.4.5
│ ├── UNMET PEER DEPENDENCY @angular/core@~2.4.5
├─┬ UNMET PEER DEPENDENCY d3@4.8.0
├── UNMET PEER DEPENDENCY node-sass@^4.0.0
├─┬ UNMET PEER DEPENDENCY rxjs@5.3.0
└── UNMET PEER DEPENDENCY zone.js@0.8.9

但是,即使在使用以下两个命令之一进行安装,然后删除node_modules&清理缓存,我仍然有未满足的依赖项。

npm install --save-dev @angular/animations @angular/common @angular/compiler @angular/core @angular/platform-browser @angular/common @angular/core d3 less rxjs zone.js

npm install --save @angular/animations @angular/common @angular/compiler @angular/core @angular/platform-browser @angular/common @angular/core d3 less rxjs zone.js

所以最重要的是,我的安装UNMET依赖项的方法是否正确?如果有人知道我的问题,我会很感激。

编辑: 使用npm版本4.2.0,这里是我与正确的ngx-charts-dag版本

的依赖关系
  "dependencies": {
    "@angular/animations": "~4.0.3",
    "@angular/common": "~4.0.3",
    "@angular/compiler": "~4.0.3",
    "@angular/core": "~4.0.3",
    "@angular/platform-browser": "~4.0.3",
    "@angular/platform-browser-dynamic": "~4.0.3",
    "d3": "4.8.0",
    "@swimlane/ngx-charts-dag": "^2.0.0",
    "rxjs": "5.3.0",
    "zone.js": “0.8.9”,
    …
  }

我仍然看到项目根目录下的未完成的对等依赖项问题与package.json中的确切版本 -

├── UNMET PEER DEPENDENCY @angular/common@4.0.3
├── UNMET PEER DEPENDENCY @angular/compiler@4.0.3
├── UNMET PEER DEPENDENCY @angular/core@4.0.3
├── UNMET PEER DEPENDENCY @angular/platform-browser@4.0.3
├── UNMET PEER DEPENDENCY @angular/platform-browser-dynamic@4.0.3
├─┬ UNMET PEER DEPENDENCY d3@4.8.0
├─┬ UNMET PEER DEPENDENCY rxjs@5.3.0
└── UNMET PEER DEPENDENCY zone.js@0.8.9

EDIT2: Mitch提供的一些修复删除了rxjs@5.3.0&的未满足的对等依赖项。 zone.js@0.8.9。这些是由已弃用的“ng2d3”引起的,它已移至ngx-charts。 “angular2-google-maps”对于zone.js@0.8.9也有一个未满足的对等依赖项。令人费解的是,在删除“ng2d3”和“angular2-google-maps”后,我收到了以下UNMET PEER DEPENDENCIES

├── UNMET PEER DEPENDENCY @angular/animations@4.0.3
├── UNMET PEER DEPENDENCY @angular/common@4.0.3
├── UNMET PEER DEPENDENCY @angular/compiler@4.0.3
├─┬ UNMET PEER DEPENDENCY @angular/compiler-cli@4.1.0
├── UNMET PEER DEPENDENCY @angular/core@4.0.3
├── UNMET PEER DEPENDENCY @angular/platform-browser@4.0.3
├── UNMET PEER DEPENDENCY @angular/platform-browser-dynamic@4.0.3
├─┬ UNMET PEER DEPENDENCY d3@4.2.2
├─┬ UNMET PEER DEPENDENCY webpack@2.5.0

这些匹配我的package.json中指定的确切版本 -

  "dependencies": {
    "@angular/animations": "4.0.3",
    "@angular/common": "4.0.3",
    "@angular/compiler": "4.0.3",
    "@angular/compiler-cli": "4.1.0",
    "@angular/core": "4.0.3",
    "@angular/platform-browser": "4.0.3",
    "@angular/platform-browser-dynamic": "4.0.3",
    "d3": "4.2.2"
  },
  "devDependencies": {
    "webpack": "2.5.0",
  }

1 个答案:

答案 0 :(得分:1)

根据ngx-charts-dag回购:

  

注意:ngx-charts-dag 2.0.0仅适用于Angular 4.x.要在Angular 2.x中使用ngx-charts-dag,请使用ngx-charts-dag 1.x。

您正在尝试使用不兼容的ngx-charts-dag@1.0.0和angular@4.x.要么将所有Angular降级到2.x,要么将ngx-charts-dag升级到2.x。