角度材料|模块的元数据版本不匹配

时间:2018-05-14 15:30:10

标签: angular angular-material metadata

我们一直在试图解决Angular Material的Metadata version mismatch for module错误,这阻止我们完成此应用程序的最终构建。作为参考,我们使用Angular4。尝试运行ng serve以便在本地运行应用时,我们会收到此错误消息。有趣的是,一旦我们运行ng serve并且由于以下错误导致构建失败,如果我们只是进入任何文件并在文件中的任何位置添加一个新的空行并保存(它会自动重新运行{{ 1}}),然后应用程序将成功编译(如控制台输出ng serve的底部所示 - 这是我们添加一个新的空白行并重新保存的地方):

webpack: Compiled successfully.

这是我们的package.json:

UserNameHere influx-archiver2 (master) > ng serve

@angular/compiler-cli@4.3.0 requires typescript@'>=2.1.0 <2.4.0' but 2.5.2 was found instead.
Using this version can result in undefined behaviour and difficult to debug problems.

Please run the following command to install a compatible version of TypeScript.

npm install typescript@'>=2.1.0 <2.4.0'

To disable this warning run "ng set warnings.typescriptMismatch=false".

** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2018-05-11T17:33:43.081Z
Hash: d5a1d43de98307f01054
Time: 20633ms
chunk {inline} inline.bundle.js (inline) 3.85 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 758 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 575 kB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 735 kB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 19.5 MB [initial] [rendered]

ERROR in Error: Metadata version mismatch for module /Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/material/core/typings/index.d.ts, found version 4, expected 3, resolving symbol MatModule in /Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/src/app/shared/mat.module.ts, resolving symbol MatModule in /Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/src/app/shared/mat.module.ts
 at Error (native)
 at syntaxError (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/compiler/bundles/compiler.umd.js:1725:34)
 at simplifyInContext (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/compiler/bundles/compiler.umd.js:24950:23)
 at StaticReflector.simplify (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/compiler/bundles/compiler.umd.js:24962:13)
 at StaticReflector.annotations (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/compiler/bundles/compiler.umd.js:24392:41)
 at _getNgModuleMetadata (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/compiler-cli/src/ngtools_impl.js:138:31)
 at _extractLazyRoutesFromStaticModule (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/compiler-cli/src/ngtools_impl.js:109:26)
 at /Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/compiler-cli/src/ngtools_impl.js:129:27
 at Array.reduce (native)
 at _extractLazyRoutesFromStaticModule (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/compiler-cli/src/ngtools_impl.js:128:10)
 at Object.listLazyRoutesOfModule (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/compiler-cli/src/ngtools_impl.js:53:22)
 at Function.NgTools_InternalApi_NG_2.listLazyRoutes (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@angular/compiler-cli/src/ngtools_api.js:91:39)
 at AotPlugin._getLazyRoutesFromNgtools (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@ngtools/webpack/src/plugin.js:240:66)
 at _donePromise.Promise.resolve.then.then.then.then.then (/Users/UserNameHere/Desktop/InfluxArchiver2/influx-archiver2/node_modules/@ngtools/webpack/src/plugin.js:493:24)
 at process._tickCallback (internal/process/next_tick.js:109:7)

webpack: Failed to compile.
webpack: Compiling...
Date: 2018-05-11T17:33:54.396Z - Hash: d473e8f60486dc05c5c4 - Time: 5079ms
5 unchanged chunks

webpack: Compiled successfully.

任何帮助将不胜感激!我们对如何专门解决此错误感到困惑,以及为什么添加新的空行允许应用编译

谢谢!

1 个答案:

答案 0 :(得分:0)

我通过升级到Angular5来解决这个问题(因为这个特殊的材料RC只与Angular5兼容。)

执行命令

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-browser@^5.0.0 @angular/platform-browser-dynamic@^5.0.0 @angular/platform-server@^5.0.0 @angular/router@^5.0.0 typescript@2.4.2 rxjs@^5.5.2

npm install typescript@2.4.2 --save-exact

然后更新package.json以利用以下工作依赖项:

"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/router": "^5.2.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "1.6.7",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "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": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }

修复了这个特殊的错误!