简体   繁体   English

找不到“AppServerModule”的 NgModule 元数据

[英]No NgModule metadata found for 'AppServerModule'

I am trying to run and build my server side rendering angular project.我正在尝试运行和构建我的服务器端渲染角度项目。 Once I have the project running locally on my machine and open it in a web browser I receive the following error:在我的机器上本地运行该项目并在 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

I have done some checking and research but I am having trouble finding where the problem is.我已经做了一些检查和研究,但我无法找到问题所在。 I am sure it is something relatively simple but would appreciate any help.我相信这是相对简单的事情,但希望得到任何帮助。 I will provide some details about a few other files.我将提供有关其他一些文件的一些详细信息。 Thank you in advance!先感谢您!

Here is the src/main.server.ts file这是 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';

Here is the src/app/app.server.module file这是 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 {}

'import' 而不是 'export' 将修复它

Had the same issue with ng10 univeral project.与 ng10 通用项目有同样的问题。 In my case I had turned bundleDependencies to false, and reverting it to true cleared up the above error.就我而言,我已将 bundleDependencies 设置为 false,并将其恢复为 true 清除了上述错误。 angular.json snippet below.下面的 angular.json 片段。

"server": {
  "builder": "@angular-devkit/build-angular:server",
  "options": {
    "outputPath": "dist/server",
    "main": "server.ts",
    "tsConfig": "tsconfig.server.json",
    "bundleDependencies": true
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM