angular - Angular 应用程序因 JitCompiler 错误而崩溃
问题描述
我接手了一个项目,并负责添加更多功能。所以我添加了一些模块和组件,当应用程序启动和运行时它崩溃了。
Uncaught Error: Component EnquiryComponent is not part of any NgModule or the module has not been imported into your module.
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._createCompiledHostTemplate (compiler.js:27198)
at compiler.js:27174
at Array.forEach (<anonymous>)
at compiler.js:27171
at Array.forEach (<anonymous>)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:27160)
at compiler.js:27088
at Object.then (compiler.js:2400)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:27087)
at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler.compileModuleAsync (compiler.js:27047)
EnquiryComponent 在 app-module.ts 中导入
import { EnquiryComponent as CustomerEnquiryComponent } from './customer/enquiry/enquiry.component';
CustomerEnquiryComponent 与其他几个组件一起被导入。我可以跑得ng compile
很好,它会在 20 秒内完成。
解决方案
您需要将其添加到模块的声明部分中:
@NgModule({
declarations:[CustomerEnquiryComponent]
})