类型错误:无法读取未定义的属性“成员" [英] TypeError: Cannot read property 'members' of undefined

查看:31
本文介绍了类型错误:无法读取未定义的属性“成员"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天开始从 Angular 4.4.4 升级到 5.1.1.我不得不升级许多其他依赖于 angular 的软件包.我收到一个错误,上下文太少,我不知道从哪里开始.有没有其他人看到这个并知道问题是什么?

$ ng serve --aot=false** NG Live Development Server 正在侦听 localhost:4200,在 http://localhost:4200/上打开浏览器 **日期:2017-12-19T15:26:36.137Z哈希:bf0b773d5dfafdd9133b时间:16934mschunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]块 {main} main.bundle.js (main) 2.93 kB [initial] [rendered]块 {polyfills} polyfills.bundle.js (polyfills) 636 字节 [initial] [rendered]chunk {scripts} scripts.bundle.js (scripts) 307 kB [initial] [rendered]块{样式}styles.bundle.js(样式)4.03 MB [initial] [rendered]chunk {vendor} vendor.bundle.js (vendor) 855 kB [initial] [rendered]TypeError 中的错误:无法读取未定义的属性成员"在 AotSummaryResolver.resolveSummary (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:32638:56)在 CompileMetadataResolver._loadSummary (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:14825:66)在 CompileMetadataResolver._getEntryComponentMetadata (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15857:66)在 C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15323:55在 Array.map (<匿名>)在 CompileMetadataResolver.getNgModuleMetadata (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15323:18)在 CompileMetadataResolver.getNgModuleSummary (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15157:52)在 C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15245:72在 Array.forEach (<匿名>)在 CompileMetadataResolver.getNgModuleMetadata (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15230:49)在visitLazyRoute (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:31061:104)在 AotCompiler.listLazyRoutes (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:31029:20)在 AngularCompilerProgram.listLazyRoutes (C:\source\app\node_modules\@angular\compiler-cli\src\transformers\program.js:156:30)在 Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\source\app\node_modules\@angular\compiler-cli\src\ngtools_api.js:44:36)在 AngularCompilerPlugin._getLazyRoutesFromNgtools (C:\source\app\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:248:66)在 Promise.resolve.then.then (C:\source\app\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:562:50)webpack:编译失败.

当我在 serve 命令中有 --aot=false 时,我发现它从 AotSummaryResolver 开始很奇怪.

这是我的 package.json:

<代码>{"name": "测试",版本":0.0.0","许可证": "麻省理工学院",脚本":{"ng": "ng","start": "ng serve --aot=false","build": "ng build","test": "ng 测试","lint": "ng lint","e2e": "ng e2e"},私人":真的,依赖关系":{"@agm/core": "^1.0.0-beta.2","@angular-devkit/schematics": "^0.0.42","@angular/animations": "5.1.1","@angular/cdk": "5.0.1","@angular/common": "5.1.1","@angular/compiler": "5.1.1","@angular/core": "5.1.1","@angular/forms": "5.1.1","@angular/http": "5.1.1","@angular/platform-b​​rowser": "5.1.1","@angular/platform-b​​rowser-dynamic": "5.1.1","@angular/platform-server": "5.1.1","@angular/router": "5.1.1","@auth0/angular-jwt": "^1.0.0-beta.9","@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.8","@ng-idle/core": "^2.0.0-beta.13","@ngrx/core": "^1.2.0","@ngrx/effects": "^4.1.1","@ngrx/entity": "^4.1.1","@ngrx/store": "^4.1.1","@ngrx/store-devtools": "^4.1.1","@schematics/angular": "^0.1.11","@schematics/schematics": "^0.0.11","angular2-counto": "^1.2.3","bootstrap": "4.0.0-beta.2","core-js": "2.4.1","d3": "^4.11.0","echarts": "^3.6.0","echarts-gl": "^1.0.0-alpha.5","font-awesome": "^4.7.0","全局": "^4.3.2","国际": "^1.2.5","jquery": "^3.2.1","时刻": "^2.19.4","ng2-dnd": "^5.0.2","popper.js": "^1.11.0","roboto-fontface": "^0.7.0","rxjs": "^5.5.2","toastr": "^2.1.2","ts-action": "^3.2.2",打字":^2.1.1","uuid": "^3.1.0","web-animations-js": "^2.2.5","纱线": "^0.24.5",zone.js":0.8.4"},开发依赖":{"@angular/cli": "1.6.1","@angular/compiler-cli": "5.1.1","@types/d3": "^4.11.0","@types/echarts": "^0.0.6","@types/hammerjs": "^2.0.34","@types/jasmine": "2.5.38","@types/jquery": "^2.0.45","@types/node": "^7.0.23","@types/toastr": "^2.1.33","@types/uuid": "^3.4.0","codelyzer": "^4.0.2","jasmine-core": "~2.5.2","jasmine-spec-reporter": "~3.2.0","json-server": "^0.12.0","jsonwebtoken": "^7.4.1",业力":~1.4.1","karma-chrome-launcher": "~2.1.1","karma-cli": "~1.0.1","karma-coverage-istanbul-reporter": "^0.2.0","karma-jasmine": "~1.1.0","karma-jasmine-html-reporter": "^0.2.2",量角器":~5.1.0","ts-node": "~2.0.0","tslint": "^5.8.0","typemoq": "^1.7.0",打字稿":2.4.2"}}

我的 angular-cli 版本是 1.6.1.

错误似乎出现在angular源代码中:

I started upgrading from Angular 4.4.4 to 5.1.1 today. I have had to upgrade a number of other packages that rely on angular as well. I get an error with so little context that I have no idea where to start. Has anyone else seen this and know what the issue is?

$ ng serve --aot=false
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2017-12-19T15:26:36.137Z
Hash: bf0b773d5dfafdd9133b
Time: 16934ms
chunk {inline} inline.bundle.js (inline) 5.79 kB [entry] [rendered]
chunk {main} main.bundle.js (main) 2.93 kB [initial] [rendered]
chunk {polyfills} polyfills.bundle.js (polyfills) 636 bytes [initial] [rendered]
chunk {scripts} scripts.bundle.js (scripts) 307 kB [initial] [rendered]
chunk {styles} styles.bundle.js (styles) 4.03 MB [initial] [rendered]
chunk {vendor} vendor.bundle.js (vendor) 855 kB [initial] [rendered]

ERROR in TypeError: Cannot read property 'members' of undefined
    at AotSummaryResolver.resolveSummary (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:32638:56)
    at CompileMetadataResolver._loadSummary (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:14825:66)
    at CompileMetadataResolver._getEntryComponentMetadata (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15857:66)
    at C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15323:55
    at Array.map (<anonymous>)
    at CompileMetadataResolver.getNgModuleMetadata (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15323:18)
    at CompileMetadataResolver.getNgModuleSummary (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15157:52)
    at C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15245:72
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.getNgModuleMetadata (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:15230:49)
    at visitLazyRoute (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:31061:104)
    at AotCompiler.listLazyRoutes (C:\source\app\node_modules\@angular\compiler\bundles\compiler.umd.js:31029:20)
    at AngularCompilerProgram.listLazyRoutes (C:\source\app\node_modules\@angular\compiler-cli\src\transformers\program.js:156:30)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\source\app\node_modules\@angular\compiler-cli\src\ngtools_api.js:44:36)
    at AngularCompilerPlugin._getLazyRoutesFromNgtools (C:\source\app\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:248:66)
    at Promise.resolve.then.then (C:\source\app\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:562:50)

webpack: Failed to compile.

I find it strange that it starts in AotSummaryResolver when I have --aot=false in the serve command.

Here is my package.json:

{
  "name": "test",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --aot=false",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.2",
    "@angular-devkit/schematics": "^0.0.42",
    "@angular/animations": "5.1.1",
    "@angular/cdk": "5.0.1",
    "@angular/common": "5.1.1",
    "@angular/compiler": "5.1.1",
    "@angular/core": "5.1.1",
    "@angular/forms": "5.1.1",
    "@angular/http": "5.1.1",
    "@angular/platform-browser": "5.1.1",
    "@angular/platform-browser-dynamic": "5.1.1",
    "@angular/platform-server": "5.1.1",
    "@angular/router": "5.1.1",
    "@auth0/angular-jwt": "^1.0.0-beta.9",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.8",
    "@ng-idle/core": "^2.0.0-beta.13",
    "@ngrx/core": "^1.2.0",
    "@ngrx/effects": "^4.1.1",
    "@ngrx/entity": "^4.1.1",
    "@ngrx/store": "^4.1.1",
    "@ngrx/store-devtools": "^4.1.1",
    "@schematics/angular": "^0.1.11",
    "@schematics/schematics": "^0.0.11",
    "angular2-counto": "^1.2.3",
    "bootstrap": "4.0.0-beta.2",
    "core-js": "2.4.1",
    "d3": "^4.11.0",
    "echarts": "^3.6.0",
    "echarts-gl": "^1.0.0-alpha.5",
    "font-awesome": "^4.7.0",
    "global": "^4.3.2",
    "intl": "^1.2.5",
    "jquery": "^3.2.1",
    "moment": "^2.19.4",
    "ng2-dnd": "^5.0.2",
    "popper.js": "^1.11.0",
    "roboto-fontface": "^0.7.0",
    "rxjs": "^5.5.2",
    "toastr": "^2.1.2",
    "ts-action": "^3.2.2",
    "typings": "^2.1.1",
    "uuid": "^3.1.0",
    "web-animations-js": "^2.2.5",
    "yarn": "^0.24.5",
    "zone.js": "0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.6.1",
    "@angular/compiler-cli": "5.1.1",
    "@types/d3": "^4.11.0",
    "@types/echarts": "^0.0.6",
    "@types/hammerjs": "^2.0.34",
    "@types/jasmine": "2.5.38",
    "@types/jquery": "^2.0.45",
    "@types/node": "^7.0.23",
    "@types/toastr": "^2.1.33",
    "@types/uuid": "^3.4.0",
    "codelyzer": "^4.0.2",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "json-server": "^0.12.0",
    "jsonwebtoken": "^7.4.1",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.1.1",
    "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-node": "~2.0.0",
    "tslint": "^5.8.0",
    "typemoq": "^1.7.0",
    "typescript": "2.4.2"
  }
}

My angular-cli version is 1.6.1.

The error seems to occur here in the angular source code: https://github.com/angular/angular/blob/b3eb1db6dd57a0820cfc94af5460ceb3fea20610/packages/compiler/src/aot/summary_resolver.ts#L68

SOLUTION

Previously I thought it was related to ng-bootstrap which was incorrect.

I found some context for it by putting a console log at line 15207 in compiler.umd.js as follows:

if (meta.entryComponents) {
    console.log(meta);
    entryComponents.push.apply(entryComponents, flattenAndDedupeArray(meta.entryComponents)
                .map(function (type) { return /** @type {?} */ ((_this._getEntryComponentMetadata(type))); }));
}

Which resulted in:

...
entryComponents: [ undefined ],
...

I had a module with entryComponents: [MdProgressSpinner] where MdProgressSpinner was not imported. When I removed it that error went away... and the next one came :)

解决方案

One of the reasons this can happen is in you app module, you have an entry components which the build process can't find a import for (in below example if I comment out the import line and leave the component then it causes this error).

这篇关于类型错误:无法读取未定义的属性“成员"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆