我试图让ngExpressEngine与JIT编译器(Angular 4.1.X)一起使用,但是有一个问题。为什么JIT需要元数据?
Error: No NgModule metadata found for 'MainModule'.
at NgModuleResolver.resolve (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/@angular/compiler/bundles/compiler.umd.js:13889:23)
at CompileMetadataResolver.getNgModuleMetadata (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/@angular/compiler/bundles/compiler.umd.js:14473:60)
at JitCompiler._loadModules (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/@angular/compiler/bundles/compiler.umd.js:25640:66)
at JitCompiler._compileModuleAndComponents (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/@angular/compiler/bundles/compiler.umd.js:25599:52)
at JitCompiler.compileModuleAsync (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/@angular/compiler/bundles/compiler.umd.js:25561:23)
at /Users/matthias/Documents/private workspace/chaoslistapi/node_modules/@nguniversal/express-engine/src/main.js:82:22
at getFactory (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/@nguniversal/express-engine/src/main.js:68:12)
at View.engine (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/@nguniversal/express-engine/src/main.js:46:13)
at View.render (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/express/lib/view.js:126:8)
at tryRender (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/express/lib/application.js:639:10)
at Function.render (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/express/lib/application.js:591:3)
at ServerResponse.render (/Users/matthias/Documents/private workspace/chaoslistapi/node_modules/express/lib/response.js:960:7)
这是我的服务器模块
import { NgModule } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { RouterModule } from '@angular/router'
import { AppModule, AppComponent } from './app/app.module'
import { SharedModule } from './app/shared/shared.module'
import { BrowserModule, Meta } from '@angular/platform-browser'
import { ServerModule } from '@angular/platform-server'
export function getLRU() {
return new Map()
}
export function getRequest() {
return Zone.current.get('req') || {}
}
export function getResponse() {
return Zone.current.get('res') || {}
}
@NgModule({
bootstrap: [ AppComponent ],
imports: [
BrowserModule.withServerTransition({
appId: 'chaoslist'
}),
ServerModule,
FormsModule,
RouterModule.forRoot([], { useHash: false }),
SharedModule.forRoot(),
AppModule
],
providers: [
{ provide: 'isBrowser', useValue: false },
{ provide: 'isNode', useValue: true },
{ provide: 'req', useFactory: getRequest },
{ provide: 'res', useFactory: getResponse },
{ provide: 'LRU', useFactory: getLRU, deps: [] },
Meta
]
})
export class MainModule {
}
我打电话给ngExpressEngine。我找到了一个JIT集成的提交,所以理论上应该这样做。这是一个新的错误还是我在这里做了一些明显的错误?
// Angular 2 Universal
import { ngExpressEngine } from '@nguniversal/express-engine';
// App
import { MainModule } from './node.module';
// Express View
this.app.engine('html', ngExpressEngine({
bootstrap: MainModule
}));