加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular4 + Material2 - 异常 Exception

发布时间:2020-12-17 08:58:55 所属栏目:安全 来源:网络整理
导读: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里提示编译失败

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/*"
      ]
    }
  }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读