【问题标题】:Angular :Metadata version mismatch for module src/app/app.module.ts, found version 3, expected 4Angular:模块 src/app/app.module.ts 的元数据版本不匹配,找到版本 3,预期版本 4
【发布时间】:2018-06-26 02:18:05
【问题描述】:

我已经从 Angular 4.0.0 迁移到 5.2.0。

在进行了建议的更改后,我发现了一个奇怪的错误,表明一些错误:

ERROR in Error: Metadata version mismatch for module /home/khalidvm/Desktop/Workspace/Front/Migration Angular 4 5/frontend_v2/src/app/app.module.ts, found version 3, expected 4
    at StaticSymbolResolver.getModuleMetadata (/home/khalidvm/Desktop/Workspace/Front/Migration Angular 4 5/frontend_v2/node_modules/@angular/compiler/bundles/compiler.umd.js:29736:34)
    at StaticSymbolResolver._createSymbolsOf (/home/khalidvm/Desktop/Workspace/Front/Migration Angular 4 5/frontend_v2/node_modules/@angular/compiler/bundles/compiler.umd.js:29468:46)
    at StaticSymbolResolver.resolveSymbol (/home/khalidvm/Desktop/Workspace/Front/Migration Angular 4 5/frontend_v2/node_modules/@angular/compiler/bundles/compiler.umd.js:29124:14)
    at StaticReflector.findSymbolDeclaration (/home/khalidvm/Desktop/Workspace/Front/Migration Angular 4 5/frontend_v2/node_modules/@angular/compiler/bundles/compiler.umd.js:31640:67)
    at StaticReflector.findDeclaration (/home/khalidvm/Desktop/Workspace/Front/Migration Angular 4 5/frontend_v2/node_modules/@angular/compiler/bundles/compiler.umd.js:31615:21)
    at Object.listLazyRoutesOfModule (/home/khalidvm/Desktop/Workspace/Front/Migration Angular 4 5/frontend_v2/node_modules/@angular/compiler-cli/src/ngtools_impl.js:51:37)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (/home/khalidvm/Desktop/Workspace/Front/Migration Angular 4 5/frontend_v2/node_modules/@angular/compiler-cli/src/ngtools_api.js:91:39)
    at AotPlugin._getLazyRoutesFromNgtools (/home/khalidvm/Desktop/Workspace/Front/Migration Angular 4 5/frontend_v2/node_modules/@angular/cli/node_modules/@ngtools/webpack/src/plugin.js:241:66)
    at _donePromise.Promise.resolve.then.then.then.then.then (/home/khalidvm/Desktop/Workspace/Front/Migration Angular 4 5/frontend_v2/node_modules/@angular/cli/node_modules/@ngtools/webpack/src/plugin.js:495:24)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:169:7)

问题似乎是有一些库需要更新。

我的 package.json 看起来像这样:

{
  "name": "nomadis",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "karma": "ng test",
    "test": "jest",
    "test:watch": "jest --watch",
    "test:ci": "jest --runInBand",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "5.2.0",
    "@angular/common": "5.2.0",
    "@angular/compiler": "5.2.0",
    "@angular/core": "5.2.0",
    "@angular/forms": "5.2.0",
    "@angular/http": "5.2.0",
    "@angular/platform-browser": "5.2.0",
    "@angular/platform-browser-dynamic": "5.2.0",
    "@angular/platform-server": "5.2.0",
    "@angular/router": "5.2.0",
    "angular-2-local-storage": "1.0.1",
    "angular2-drag-scroll": "1.2.6",
    "angular2-jwt": "0.2.3",
    "angular2-modal": "2.0.3",
    "angular2-multiselect-dropdown": "1.3.6",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "file-saver": "1.3.3",
    "font-awesome": "4.7.0",
    "hammerjs": "2.0.8",
    "jest-preset-angular": "2.0.5",
    "json2typescript": "0.9.5",
    "lodash": "^4.12.0",
    "moment": "2.18.1",
    "ng-http-interceptor": "4.0.0",
    "ng2-smart-table": "1.1.0",
    "ngx-bootstrap": "1.6.6",
    "ngx-filesaver": "0.0.2",
    "ngx-pagination": "3.0.1",
    "ngx-tooltip": "0.0.9",
    "npm": "^5.2.0",
    "proxy-polyfill": "0.1.7",
    "rxjs": "^5.1.0",
    "sha1": "1.1.1",
    "smoothscroll-polyfill": "0.3.5",
    "web-animations-js": "2.2.5",
    "zone.js": "^0.8.8"
  },
  "devDependencies": {
    "@angular/cli": "^1.2.0",
    "@angular/compiler-cli": "^4.0.0",
    "@types/jasmine": "2.5.38",
    "@types/jest": "^20.0.5",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "jest": "^20.0.4",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.0.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.0",
    "ts-jest": "^20.0.7",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "2.4.2"
  },
  "jest": {
    "preset": "jest-preset-angular",
    "setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts",
    "transformIgnorePatterns": [
      "node_modules/(?!json2typescript|angular2-multiselect-dropdown|ngx-filesaver|ngx-bootstrap|angular2-drag-scroll)"
    ]
  }
}

如果有依赖更新,那么ut是什么?

我已经尝试调试,以了解问题的根源。但我没有抓到蚂蚁。

我正在构建我的应用程序: Angular-CLI:1.6.0 节点:8.0.0 npm : 5.3.0

建议?

【问题讨论】:

    标签: angular npm node-modules package.json


    【解决方案1】:

    如果您在执行npm install 时读取输出,它会准确告诉您依赖项失败的位置:

    npm WARN angular2-jwt@0.2.3 requires a peer of @angular/core@^2.0.0||^4.0.0 but none was installed.
    npm WARN angular2-jwt@0.2.3 requires a peer of @angular/http@^2.0.0||^4.0.0 but none was installed.
    npm WARN ngx-tooltip@0.0.9 requires a peer of @angular/core@^2.0.0 but none was installed.
    npm WARN angular2-drag-scroll@1.2.6 requires a peer of @angular/common@^2.3.1 but none was installed.
    npm WARN angular2-drag-scroll@1.2.6 requires a peer of @angular/compiler@^2.3.1 but none was installed.
    npm WARN angular2-drag-scroll@1.2.6 requires a peer of @angular/core@^2.3.1 but none was installed.
    npm WARN angular2-modal@2.0.3 requires a peer of @angular/core@^2.1.1 but none was installed.
    npm WARN angular2-modal@2.0.3 requires a peer of @angular/common@^2.1.1 but none was installed.
    npm WARN ng2-smart-table@1.1.0 requires a peer of @angular/common@^4.0.0 but none was installed.
    npm WARN ng2-smart-table@1.1.0 requires a peer of @angular/core@^4.0.0 but none was installed.
    npm WARN ng2-smart-table@1.1.0 requires a peer of @angular/forms@^4.0.0 but none was installed.
    npm WARN codelyzer@2.0.1 requires a peer of @angular/compiler@^2.3.1 || >=4.0.0-beta <5.0.0 but none was installed.
    npm WARN codelyzer@2.0.1 requires a peer of @angular/core@^2.3.1 || >=4.0.0-beta <5.0.0 but none was installed.
    npm WARN @angular/compiler-cli@4.4.6 requires a peer of @angular/compiler@4.4.6 but none was installed.
    npm WARN @angular/compiler-cli@4.4.6 requires a peer of @angular/core@4.4.6 but none was installed.
    npm WARN @schematics/angular@0.1.13 requires a peer of @angular-devkit/schematics@0.0.46 but none was installed.
    npm WARN @schematics/schematics@0.0.13 requires a peer of @angular-devkit/schematics@0.0.46 but none was installed.
    

    回滚到 @angular4 或用它们的 @angular5 等效项更新/替换这些库。

    【讨论】:

    • 仍然不知道哪个是错的(因为我告诉我第一个错误 -mine- 是寻找一些 4 版本,它找到了一个版本 3)
    • 所有这些都是错误的。 angular5 不向后兼容 angular4。显然,您包含的库不适用于 angular5。您需要更新这些。
    • 例如,angular2-jwt 有一个开放的 pull request 来支持 ng5:github.com/auth0/angular2-jwt/issues/449。检查这些库是否正在工作(或已经)支持 ng5。如果他们完全停止更新库,我建议用替代品替换它们。
    • 或者集成这个 PR:github.com/auth0/angular2-jwt/pull/472/files,然后重新构建包(确保测试首先通过)。在本地部署包(即使用符号链接进行本地部署)
    • angular2-modal 导致问题
    猜你喜欢
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-16
    • 2020-01-09
    • 2018-04-19
    • 2018-08-31
    相关资源
    最近更新 更多