我正在尝试运行和构建我的服务器端渲染角度项目。一旦我在我的机器上本地运行项目并在 Web 浏览器中打开它,我会收到以下错误:
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
我已经进行了一些检查和研究,但我无法找到问题所在。我相信这是相对简单的事情,但希望能提供任何帮助。我将提供有关其他一些文件的一些详细信息。先感谢您!
这是 src/main.server.ts 文件
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';
这是 src/app/app.server.module 文件
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 {}