Node.js R3InjectorError(AppServerModule)InjectionToken编译器选项没有提供程序
我得到以下错误:Node.js R3InjectorError(AppServerModule)InjectionToken编译器选项没有提供程序,node.js,angular,server-side-rendering,Node.js,Angular,Server Side Rendering,我得到以下错误: render error Error [NullInjectorError]: R3InjectorError(AppServerModule)[RouterModule -> Router -> NgModuleFactoryLoader -> Compiler -> InjectionToken compilerOptions -> InjectionToken compilerOptions -> InjectionToken comp
render error Error [NullInjectorError]: R3InjectorError(AppServerModule)[RouterModule -> Router -> NgModuleFactoryLoader -> Compiler -> InjectionToken compilerOptions -> InjectionToken compilerOptions -> InjectionToken compilerOptions]:
NullInjectorError: No provider for InjectionToken compilerOptions!
我遵循了提供的说明,但似乎需要添加的调整很少,比如使用domino
模拟document
对象来工作。让我很难找出问题所在的一个问题是,main.js
render error Error [NullInjectorError]: R3InjectorError(AppServerModule)[RouterModule -> Router -> NgModuleFactoryLoader -> Compiler -> InjectionToken compilerOptions -> InjectionToken compilerOptions -> InjectionToken compilerOptions]:
NullInjectorError: No provider for InjectionToken compilerOptions!
at ɵɵinject (<project-dir>\dist\apps\ui\server\main.js:219196:57)
at injectArgs (<project-dir>\dist\apps\ui\server\main.js:219291:23)
at Object.factory (<project-dir>\dist\apps\ui\server\main.js:229671:52)
at R3Injector.hydrate (<project-dir>\dist\apps\ui\server\main.js:229582:35)
at R3Injector.get (<project-dir>\dist\apps\ui\server\main.js:229404:33) {
ngTempTokenPath: null,
ngTokenPath: [
'RouterModule',
'Router',
'NgModuleFactoryLoader',
'Compiler',
'InjectionToken compilerOptions',
'InjectionToken compilerOptions',
'InjectionToken compilerOptions'
]
} undefined
下面是app.server.module.ts
import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server';
import { IonicServerModule } from '@ionic/angular-server'; // i added this thinking it might help
import { AppComponent } from './app.component';
import { AppModule } from './app.module';
@NgModule({
imports: [AppModule, ServerModule, IonicServerModule],
bootstrap: [AppComponent],
})
export class AppServerModule {}
任何建议都将不胜感激
编辑:
原来错误来自下面的deps:[[Optional(),COMPILER\u OPTIONS]],
:
@NgModule({
declarations: [DynamicComponentDirective],
exports: [DynamicComponentDirective],
})
export class DynamicComponentModule {
static forRoot(metadata: NgModule): ModuleWithProviders<DynamicComponentModule> {
console.log('compiler options');
return {
ngModule: DynamicComponentModule,
providers: [
{
provide: Compiler,
useFactory: createJitCompiler,
/**
* This leads to the following error:
* R3InjectorError(AppServerModule)[RouterModule -> Router -> NgModuleFactoryLoader -> Compiler -> InjectionToken compilerOptions -> InjectionToken compilerOptions -> InjectionToken compilerOptions]: NullInjectorError: No provider for InjectionToken compilerOptions!
*/
// deps: [[Optional(), COMPILER_OPTIONS]],
},
{
provide: DynamicComponentOptions,
useValue: {
ngModuleMetadata: metadata,
},
},
],
};
}
}
不知道怎么做,有人能帮忙吗?结果是SSR的
angular.json
配置有问题,与解决问题的配置相同
@NgModule({
declarations: [DynamicComponentDirective],
exports: [DynamicComponentDirective],
})
export class DynamicComponentModule {
static forRoot(metadata: NgModule): ModuleWithProviders<DynamicComponentModule> {
console.log('compiler options');
return {
ngModule: DynamicComponentModule,
providers: [
{
provide: Compiler,
useFactory: createJitCompiler,
/**
* This leads to the following error:
* R3InjectorError(AppServerModule)[RouterModule -> Router -> NgModuleFactoryLoader -> Compiler -> InjectionToken compilerOptions -> InjectionToken compilerOptions -> InjectionToken compilerOptions]: NullInjectorError: No provider for InjectionToken compilerOptions!
*/
// deps: [[Optional(), COMPILER_OPTIONS]],
},
{
provide: DynamicComponentOptions,
useValue: {
ngModuleMetadata: metadata,
},
},
],
};
}
}
@NgModule({
imports: [
...
],
bootstrap: [...],
providers: [/* I think i need to add a provider for it here */],
})
export class AppServerModule {}