在Angular v6中,当我尝试构建我的库时,我遇到了一个非常不具描述性的BUILD ERROR无法读取null的属性’type’
BUILD ERROR
Cannot read property 'type' of null
TypeError: Cannot read property 'type' of null
at /Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:15378:27
at Array.forEach (<anonymous>)
at removeSummaryDuplicates (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:15377:11)
at TemplateParser.tryParseHtml (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14806:34)
at TemplateParser.tryParse (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14799:21)
at TemplateParser.parse (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:14780:27)
at AotCompiler._parseTemplate (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20483:43)
at AotCompiler._createTypeCheckBlock (/Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20250:23)
at /Users/John/apps/tests/service-work/node_modules/@angular/compiler/bundles/compiler.umd.js:20220:27
at Array.forEach (<anonymous>)
已经解决了这个问题,我正在发布这篇文章,以帮助其他人遇到这个问题.
最佳答案 更新
似乎我对这个问题的诊断是不正确的(现在已经很久了,我记不清楚我是如何修复的). Check out this issue in the Angular repo听起来像是正确的诊断,
原始答案:
所以在经过大量的调试之后,我发现了它:
我的自定义库,我们称之为库A,将另一个自定义库库B导入库A的NgModule.库B从它的主要NgModule中导出了几个组件和模块.问题是,当库B从它的NgModule导出组件和模块时,我也无法通过javascript / typescript导出这些组件和模块.解决方案是确保通过我在NgModule中导出的typescript导出任何组件/模块.
示例问题代码
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LibraryBComponent } from './library-b.component';
@NgModule({
imports: [CommonModule],
declarations: [LibraryBComponent],
exports: [LibraryBComponent],
})
export class LibraryBModule {}
解决方案代码
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { LibraryBComponent } from './library-b.component';
export { LibraryBComponent } // <-- addition
@NgModule({
imports: [CommonModule],
declarations: [LibraryBComponent],
exports: [LibraryBComponent],
})
export class LibraryBModule {}