Angular4 + Material2 - 异常 Exception

前端之家收集整理的这篇文章主要介绍了Angular4 + Material2 - 异常 Exception前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Unexpected value '…' imported by the module '…'. Please add a @NgModule annotation

Unexpected value 'CdkTableModule' imported by the module 'AppModule'. Please add a @NgModule annotation


ng s启动完,在命令行和浏览器console里提示编译失败:

WARNING in ./~/_@angular_core@4.3.5@@angular/core/@angular/core.es5.js
5646:15-36 Critical dependency: the request of a dependency is an expression

WARNING in ./~/_@angular_core@4.3.5@@angular/core/@angular/core.es5.js
5662:15-102 Critical dependency: the request of a dependency is an expression

ERROR in Error encountered resolving symbol values statically. Function calls ar
e not supported. Consider replacing the function or lambda with a reference to a
n exported function (position 194:50 in the original .ts file),resolving symbol
 NgModule in F:/TRANSFORMERS/projectpower/angular4webpack3/node_modules/@angular
/cdk/node_modules/@angular/core/core.d.ts,resolving symbol CdkTableModule in F:
/TRANSFORMERS/projectpower/angular4webpack3/node_modules/@angular/cdk/typings/in
dex.d.ts,resolving symbol CdkTableModule in F:/TRANSFORMERS/projectpower/angula
r4webpack3/node_modules/@angular/cdk/typings/index.d.ts
webpack: Failed to compile.



用node的npm按装完Angular4,在安装Material2,各个组件版本如package.json所示,出现上述异常,但是没有安装Material2之前,此Angular4的app是可以正常工作的,

分析应该是此Material2的版本2.0.0-beta.8和此Angular4的版本不兼容导致的,


package.json

{
  "name": "angular4webpack3","version": "0.0.1","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.0.0","@angular/cdk": "^2.0.0-beta.8",
    "@angular/common": "^4.0.0","@angular/compiler": "^4.0.0","@angular/core": "^4.0.0","@angular/forms": "^4.0.0","@angular/http": "^4.0.0","@angular/material": "^2.0.0-beta.8",
    "@angular/platform-browser": "^4.0.0","@angular/platform-browser-dynamic": "^4.0.0","@angular/router": "^4.0.0","core-js": "^2.4.1","hammerjs": "^2.0.8","rxjs": "^5.4.1","zone.js": "^0.8.14"
  },"devDependencies": {
    "@angular/cli": "1.2.3","@angular/compiler-cli": "^4.0.0",
    "@angular/language-service": "^4.0.0","@types/jasmine": "~2.5.53","@types/jasminewd2": "~2.0.2","@types/node": "~6.0.60","codelyzer": "~3.0.1","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.0.4","tslint": "~5.3.2","typescript": "~2.3.3"
  }
}



解决方法

https://stackoverflow.com/questions/44138317/unexpected-value-imported-by-the-module-please-add-a-ngmodule-anno

https://github.com/angular/angular-cli/issues/6429

https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/linked-library.md

You should list all the peer dependencies that your library uses in./tsconfig.json,pointing them at the local copy in the appsnode_modulesfolder. This ensures that you all will always load the local copies of the modules your library asks for

{
  "compilerOptions": {
    // ...
    // Note: these paths are relative to `baseUrl` path.
    "paths": {
      "@angular/*": [
        "../node_modules/@angular/*"
      ]
    }
  }
}
原文链接:https://www.f2er.com/angularjs/146436.html

猜你在找的Angularjs相关文章