7

我在运行ng build命令时遇到错误。删除 node_modules 文件夹和 npm installe 给出以下警告

npm WARN angular2-cool-storage@3.1.2 requires a peer of @angular/core@5.0.0 but none was installed.
npm WARN angular2-cool-storage@3.1.2 requires a peer of @angular/common@^5.0.0 but none was installed.

对于 ng build 下面的 id 详细错误:

模块 /node_modules/angular2-cool-storage/index.d.ts 的元数据版本不匹配错误,找到版本 4,预期为 3,解析 /src/app/app.module.ts 中的符号 AppModule 解析 /src/ 中的符号 AppModule应用程序/app.module.ts

Package.json 是

{
  "name": "nova-angular",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.4.3",
    "@angular/cdk": "^2.0.0-beta.12",
    "@angular/common": "^4.4.3",
    "@angular/compiler": "^4.4.3",
    "@angular/core": "^4.4.3",
    "@angular/forms": "^4.4.3",
    "@angular/http": "^4.4.3",
    "@angular/material": "^2.0.0-beta.12",
    "@angular/platform-browser": "^4.4.3",
    "@angular/platform-browser-dynamic": "^4.4.3",
    "@angular/router": "^4.4.3",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.29",
    "angular2-cool-storage": "^3.1.0",
    "angular2-jwt": "^0.2.3",
    "bootstrap": "^3.3.7",
    "classlist.js": "^1.1.20150312",
    "core-js": "^2.5.0",
    "ng2-cookies": "^1.0.12",
    "ng2-truncate": "^1.3.10",
    "rxjs": "^5.4.2",
    "tslint-fix": "^0.1.0",
    "zone.js": "^0.8.16"
  },
  "devDependencies": {
    "@angular/cli": "1.3.2",
    "@angular/compiler-cli": "^4.4.3",
    "@angular/language-service": "^4.4.3",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^8.0.26",
    "codelyzer": "^3.1.2",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-junit-reporter": "^1.2.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "protractor": "~5.1.2",
    "ts-node": "~3.3.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2",
    "typings": "^2.1.1"
  }
}

早些时候我使用了 angular2-cool-storage,现在安装和使用ng2-cookies ng build 失败了。请建议我一个解决方案。

4

3 回答 3

4

似乎存在包兼容性问题,您应该按照本指南将包升级到 Angular 5 以使包兼容版本,我已经尝试过了,效果很好

npm install @angular/animations@^5.0.0 @angular/common@^5.0.0 @angular/compiler@^5.0.0 @angular/compiler-cli@^5.0.0 @angular/core@^5.0.0 @ angular/forms@^5.0.0 @angular/http@^5.0.0 @angular/platform-b​​rowser@^5.0.0 @angular/platform-b​​rowser-dynamic@^5.0.0 @angular/platform-server@^5.0 .0 @angular/router@^5.0.0 typescript@2.4.2 rxjs@^5.5.2

于 2017-11-27T07:21:26.053 回答
2

消息似乎很清楚:您需要一个至少为 5.0.0 的 angular core 和 common 版本。

您的包文件显示 4.4.3 版本。

尝试更新您的软件包,或降级您的依赖项,然后再试一次!

于 2017-11-07T13:00:34.210 回答
1

为了包的一致性,我更新了我的 package.json 文件。从包名称中删除了插入符号(^),因此现在它不更新包头。它强制 npm 仅使用指定的版本。

"angular2-cool-storage": "^3.1.0" => "angular2-cool-storage": "3.1.0"

检查早期与相同角度版本兼容的包版本,如果发生包的自动升级,请在 package.json 中指定那些不带 ^ 的条目Metadata version mismatch

于 2018-02-09T13:48:05.460 回答