I am facing an issue while trying to run and build my Angular project with server-side rendering. Whenever I launch the project on my local machine and open it in a web browser, I encounter the following error message:
Error: No NgModule metadata found for 'AppServerModule'.
at NgModuleResolver.resolve (/Users/user/Projects/myproject/node_modules/@angular/compiler/bundles/compiler.umd.js:22963:27)
at CompileMetadataResolver.getNgModuleMetadata (/Users/user/Projects/myproject/node_modules/@angular/compiler/bundles/compiler.umd.js:22066:47)
at JitCompiler._loadModules (/Users/user/Projects/myproject/node_modules/@angular/compiler/bundles/compiler.umd.js:28255:55)
at JitCompiler._compileModuleAndComponents (/Users/user/Projects/myproject/node_modules/@angular/compiler/bundles/compiler.umd.js:28236:40)
at JitCompiler.compileModuleAsync (/Users/user/Projects/myproject/node_modules/@angular/compiler/bundles/compiler.umd.js:28196:41)
at CompilerImpl.compileModuleAsync (/Users/user/Projects/myproject/node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js:339:35)
at CommonEngine.<anonymous> (/Users/user/Projects/myproject/node_modules/@nguniversal/express-engine/bundles/express-engine.umd.js:95:69)
at step (/Users/user/Projects/myproject/node_modules/tslib/tslib.js:136:27)
at Object.next (/Users/user/Projects/myproject/node_modules/tslib/tslib.js:117:57)
at /Users/user/Projects/myproject/node_modules/tslib/tslib.js:110:75
Despite doing some investigations and research, I am struggling to pinpoint the exact cause of this error. I believe it could be a minor issue but any assistance would be greatly appreciated. Below are details about a couple of other files. Thank you for your help!
Here is the content of src/main.server.ts file:
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
export { AppServerModule } from './app/app.server.module';
export { renderModule, renderModuleFactory } from '@angular/platform-server';
And here is the code in src/app/app.server.module file:
import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server';
import { AppModule } from './app.module';
import { AppComponent } from './app.component';
@NgModule({
imports: [
AppModule,
ServerModule,
],
bootstrap: [AppComponent],
})
export class AppServerModule {}