angular报错ERROR Error Uncaught in promise Error The NgModule MainModule needs to be compiled using the JIT compiler but angularcompiler is not available怎么解决
这个错误通常是因为在使用 AOT 编译时,没有正确配置应用程序以使用 JIT 编译器。
要解决这个问题,可以尝试以下几个步骤:
-
确保在应用程序的
tsconfig.json文件中,"angularCompilerOptions"的AOT属性为true。 -
确保在应用程序的
main.ts文件中,platformBrowserDynamic().bootstrapModule()方法使用了JitCompilerFactory。
例如:
import { JitCompilerFactory } from '@angular/compiler';
...
const compilerFactory = new JitCompilerFactory();
const compiler = compilerFactory.createCompiler();
...
platformBrowserDynamic().bootstrapModule(AppModule, {
compiler: compiler
})
- 确保在应用程序的
app.module.ts文件中,导入了BrowserAnimationsModule和NoopAnimationsModule。
例如:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
...
@NgModule({
imports: [
...
BrowserAnimationsModule,
NoopAnimationsModule,
...
],
...
})
export class AppModule { }
如果以上步骤都无法解决问题,可以尝试重新安装 @angular/compiler 依赖项,或者升级到最新版本
原文地址: https://www.cveoy.top/t/topic/g9Jx 著作权归作者所有。请勿转载和采集!