如何解决这个错误?为什么我收到此错误?

时间:2018-02-05 13:27:40

标签: angular dependencies angular5

my `package.json` file is

    {
      "name": "lg-app",
      "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.6",
        "@angular/cdk": "^5.1.1",
        "@angular/common": "^4.2.4",
        "@angular/compiler": "^4.2.4",
        "@angular/core": "^4.2.4",
        "@angular/forms": "^4.2.4",
        "@angular/http": "^4.2.4",
        "@angular/material": "^5.1.1",
        "@angular/platform-browser": "^4.2.4",
        "@angular/platform-browser-dynamic": "^4.2.4",
        "@angular/router": "^4.2.4",
        "angular-4-data-table": "^0.4.3",
        "bootstrap": "^4.0.0-beta.3",
        "core-js": "^2.4.1",
        "rxjs": "^5.4.2",
        "zone.js": "^0.8.14"
      },
      "devDependencies": {
        "@angular/cli": "^1.6.6",
        "@angular/compiler-cli": "^4.2.4",
        "@angular/language-service": "^4.2.4",
        "@types/jasmine": "~2.5.53",
        "@types/jasminewd2": "~2.0.2",
        "@types/node": "~6.0.60",
        "codelyzer": "~3.2.0",
        "jasmine-core": "~2.6.2",
        "jasmine-spec-reporter": "~4.1.0",
        "karma": "~1.7.0",
        "karma-chrome-launcher": "~2.1.1",
        "karma-cli": "~1.0.1",
        "karma-coverage-istanbul-reporter": "^1.2.1",
        "karma-jasmine": "~1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "~5.1.2",
        "ts-node": "~3.2.0",
        "tslint": "~5.7.0",
        "typescript": "~2.3.3"
      }
    }

这是我的package.json文件。我也升级了cdk任何角度材料,但它没有用。

  

错误中的错误:模块E的元数据版本不匹配:/ angular2 / lg-app / node_mod       ules/@angular/material/form-field/typings/index.d.ts,发现版本4,预期       3,解析符号AppModule在E:/angular2/lg-app/src/app/app.module.ts,resol       ving符号AppModule在E:/angular2/lg-app/src/app/app.module.ts           at syntaxError(E:\ angular2 \ lg-app \ node_modules \ @angular \ compiler \ bundles \ co       mpiler.umd.js:1729:34)           在simplifyInContext(E:\ angular2 \ lg-app \ node_modules \ @angular \ compiler \ bund       LES \ compiler.umd.js:24979:23)           在StaticReflector.simplify(E:\ angular2 \ lg-app \ node_modules \ @angular \ compil       呃\包\ compiler.umd.js:24991:13)           在StaticReflector.annotations(E:\ angular2 \ lg-app \ node_modules \ @angular \ com       堆垛机\束\ compiler.umd.js:24418:41)           at _getNgModuleMetadata(E:\ angular2 \ lg-app \ node_modules \ @angular \ compiler-c       李\ SRC \ ngtools_impl.js:138:31)           at _extractLazyRoutesFromStaticModule(E:\ angular2 \ lg-app \ node_modules \ @angu       拉尔\编译-CLI \ SRC \ ngtools_impl.js:109:26)           at Object.listLazyRoutesOfModule(E:\ angular2 \ lg-app \ node_modules \ @angular \ c       ompiler-CLI \ SRC \ ngtools_impl.js:53:22)           在Function.NgTools_InternalApi_NG_2.listLazyRoutes(E:\ angular2 \ lg-app \ node)       _modules \ @angular \编译-CLI \ SRC \ ngtools_api.js:91:39)           在AotPlugin._getLazyRoutesFromNgtools(E:\ angular2 \ lg-app \ node_modules \ @ngt       ools \的WebPack \ SRC \ plugin.js:241:66)           在_donePromise.Promise.resolve.then.then.then.then.then(E:\ angular2 \ lg-app       \ node_modules \ @ngtools \的WebPack的\ src \ plugin.js:495:24)           在

2 个答案:

答案 0 :(得分:1)

您遇到此错误,因为您有不同的角度包版本。所有角度包都应该是^ 4.2.4或^ 5.1.1。

在做出决定之后,您应该使用Angular 4或Angular 5的包。这不是强制性的,因为Angular 4的许多包与Angular 5一起使用(但不是相反)。

<强>更新

在做任何备份之前

如果要将应用程序更新到5.1.1,我建议您手动更改package.json,将所有@angular软件包从“^ 4.2.4”更改为“^ 5.1.1”。您还必须在devDependencies中更改@ angular / compiler-cli和@ angular / language-service。

删除node_modules文件夹并运行npm install

然后将angular-4-data-table更新为https://github.com/ggmod/angular-5-data-table

答案 1 :(得分:0)

正如gmazzotti已经提到的,你需要有匹配的版本。

对于像您这样的Angular CLI用户,有一个很好的资源here,您可以在其中比较使用不同版本的Angular CLI生成的项目之间的包,配置文件等。例如,假设您要将使用Angular CLI 1.5.0创建的项目升级到最新的Angular CLI(现在是1.6.7),您在repo中选择这两个分支,区分它们并得到这个很好的摘要一切都发生了变化:difference between 1.5.0 and 1.6.7