Angular4 + Material2 - 异常 Exception

5 篇文章 0 订阅
1 篇文章 0 订阅

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 apps node_modules folder. 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/*"
      ]
    }
  }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值