Encountered an error while resolving symbol values statically. The function '
DataModule
' is not supported. Consider using a reference to an exported function instead of a function or lambda, resolving the symbolDataModuleRoot
in, resolving symbolE:/shopify-client/src/app/app.module.ts
AppModule
in, resolving symbolE:/shopify-client/src/app/app.module.ts
AppModule
inE:/shopify-client/src/app/app.module.ts
Every time I build my project with Angular CLI, I encounter this error. It's frustrating that it only appears once when I start ng serve
, and then the subsequent updates do not throw an error. However, this often means I cannot proceed with just the build command because the initial run results in an error that prevents file output. I created DataModule as a module and followed the Angular documentation to create the forRoot method.
export function DataModuleRoot(){
return DataModule.forRoot({});
}
@NgModule({
declarations: [
AppComponent,
HomeComponent,
NavtreeComponent,
JsonifyPipe,
DebugPipe,
PanelsComponent,
IsolateScrollDirective
],
imports: [
BrowserModule,
AppRoutingModule,
HttpModule,
DataModuleRoot(),
PagesModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Here is the implementation of DataModule:
@NgModule({
imports: [
CommonModule
],
declarations: [],
providers: [DataService]
})
export class DataModule {
constructor( @Optional() @SkipSelf() parentModule: DataModule) {
if (parentModule) {
throw new Error(
'DataModule is already loaded. Import it in the AppModule only');
}
}
static forRoot( config: any = {}): ModuleWithProviders {
const io: Function = function () { };
const host = (window as any).devHost || config.host || location.origin
const socket: Socket = false ? io(host) : {
id: '',
on: function () { },
off: function () { },
emit: function () { },
isFailed: false
};
(window as any).socket = socket;
return {
ngModule: DataModule,
providers: [
{
provide: DataServiceConfig,
useValue: {
socket: socket,
host: host,
globalCache: {},
globalSettings: {},
}
}
]
};
}
}
I have researched similar issues on StackOverflow, but none of them addressed my specific problem.
- I did not use any external libraries. This module was created following the Angular IO documentation.
- I did not utilize a factory.