Javascript 角度9-必须传入NgModule或NgModuleFactory才能进行引导
我将Angular应用程序从v6更新到v9,在测试时它确实正常,但当我将其部署到暂存服务器时,出现以下错误: 必须传入要引导的NgModule或NgModuleFactory 我已经搜索了很多关于它的信息,但我不知道在这里能做些什么 ./server.ts: ./webpack.server.config.js ./src/tsconfig.server.json ./src/main.server.ts: ./src/app/app.module.ts ./src/app/app.server.module.ts: angular.jsonJavascript 角度9-必须传入NgModule或NgModuleFactory才能进行引导,javascript,angular,angular-universal,Javascript,Angular,Angular Universal,我将Angular应用程序从v6更新到v9,在测试时它确实正常,但当我将其部署到暂存服务器时,出现以下错误: 必须传入要引导的NgModule或NgModuleFactory 我已经搜索了很多关于它的信息,但我不知道在这里能做些什么 ./server.ts: ./webpack.server.config.js ./src/tsconfig.server.json ./src/main.server.ts: ./src/app/app.module.ts ./src/app/app.server
使用Ivy,您需要更改server.ts执行引导的方式 看起来您尚未迁移角度ssr文件。我们也遇到了同样的问题,但我们当时没有使用express engine,因此我们最终删除了与ssr server.ts、main.server.ts等相关的文件,。。。并运行以下命令以允许angular修改/创建所有必要的文件
ng add @nguniversal/express-engine
然后,我们修改了server.ts,以便在需要时添加自定义代码
如果您想在不运行命令的情况下手动执行所有操作,请查看一下Ivy,您需要更改server.ts执行引导的方式 看起来您尚未迁移角度ssr文件。我们也遇到了同样的问题,但我们当时没有使用express engine,因此我们最终删除了与ssr server.ts、main.server.ts等相关的文件,。。。并运行以下命令以允许angular修改/创建所有必要的文件
ng add @nguniversal/express-engine
然后,我们修改了server.ts,以便在需要时添加自定义代码
如果您想在不运行命令的情况下手动执行所有操作,请查看我目前实际上也遇到了同样的问题。如果我找到答案,将在此处更新。如何构建应用程序?@varundhariyal NODE\u OPTIONS=\-max old space size=8192\npm run build:modernizer&&ng build-configuration=site dev&&ng run site:server-configuration=site dev&&npm run webpack:dev&&gulp后期处理和npm run build:sitemap./sitemap.xml./dist/browser/&cp./robots.txt./dist/browser/I目前实际上也有同样的问题。如果我找到答案,将在此处更新。如何构建应用程序?@varundhariyal NODE\u OPTIONS=\-max old space size=8192\npm run build:modernizer&&ng build-configuration=site dev&&ng run site:server-configuration=site dev&&npm run webpack:dev&&gulp后期处理和npm run build:sitemap./sitemap.xml./dist/browser/&cp./robots.txt./dist/browser/hi David.Hmmm,是的。我已经尝试过删除所有与之相关的文件,然后运行上面描述的命令。但是,是的,我没有修改server.ts文件。如果我明白了,我应该多做点什么吗?如果我错了,请纠正我。@dmd开发您的server.ts文件不应再引用AppServerModuleNgFactory。如果您已经获得了由命令创建的server.ts的新版本,那么您只需要对该文件的旧版本进行任何自定义,因为我没有对AppServerModuleNgFactory的任何引用,并且命令为我制作了所有文件。在上一个版本中,我没有对server.ts文件做任何更改,它可以自动正常工作。我可以发布server.ts文件,如果你愿意,也许你会看到一些东西。我已经尝试过删除所有与之相关的文件,然后运行上面描述的命令。但是,是的,我没有修改server.ts文件。如果我明白了,我应该多做点什么吗?如果我错了,请纠正我。@dmd开发您的server.ts文件不应再引用AppServerModuleNgFactory。如果您已经获得了由命令创建的server.ts的新版本,那么您只需要对该文件的旧版本进行任何自定义,因为我没有对AppServerModuleNgFactory的任何引用,并且命令为我制作了所有文件。在上一个版本中,我没有对server.ts文件做任何更改,它可以自动正常工作。我可以发布server.ts文件,如果您愿意,也许您会看到一些东西。
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "commonjs",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
"angularCompilerOptions": {
"entryModule": "app/app.server.module#AppServerModule"
}
}
export { AppServerModule } from './app/app.server.module';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { registerLocaleData, isPlatformBrowser } from '@angular/common';
import { NgModule, PLATFORM_ID, Inject, APP_ID, } from '@angular/core';
import { NgxMaskModule } from 'ngx-mask';
// configure language
import ptBr from '@angular/common/locales/pt';
registerLocaleData(ptBr);
import { AppComponent } from './app.component';
import { CoreModule } from './core/core.module';
import { LayoutModule } from './layout/layout.module';
import { PagesModule } from './pages/pages.module';
import { SharedModule } from './shared/shared.module';
import { AgmCoreModule } from '@agm/core';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
import moment = require('moment');
moment.locale('pt-BR');
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule.withServerTransition({appId: 'site'}),
BrowserAnimationsModule,
CoreModule,
LayoutModule,
PagesModule,
SharedModule,
NgxMaskModule.forRoot(),
AgmCoreModule.forRoot({
apiKey: ''
}),
ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production })
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(
@Inject(PLATFORM_ID) private platformId: Object,
@Inject(APP_ID) private appId: string) {
const platform = isPlatformBrowser(platformId) ?
'in the browser' : 'on the server';
console.log(`Running ${platform} with appId=${appId}`);
}
}
/**
This is the App loaded for the server render
express-js will load this file instead of AppModule directly.
**/
import { NgModule } from '@angular/core';
import { ServerModule } from '@angular/platform-server';
import { AppModule } from './app.module';
import { AppComponent } from './app.component';
import { ModuleMapLoaderModule } from '@nguniversal/module-map-ngfactory-loader';
// We get the zone properties passed from express application
// @see server.ts
export function getRequest() {
return Zone.current.get('req') || {};
}
export function getResponse() {
return Zone.current.get('res') || {};
}
@NgModule({
imports: [
AppModule,
ServerModule,
ModuleMapLoaderModule,
],
bootstrap: [AppComponent],
providers: [
{ provide: 'req', useFactory: getRequest },
{ provide: 'res', useFactory: getResponse }
]
})
export class AppServerModule { }
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"site": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/browser",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets",
"src/manifest.json"
],
"styles": [
"node_modules/ngx-owl-carousel-o/lib/styles/prebuilt-themes/owl.carousel.min.css",
"node_modules/ngx-owl-carousel-o/lib/styles/prebuilt-themes/owl.theme.default.min.css",
"src/styles.scss"
],
"scripts": [
"src/assets/scripts/modernizr/modernizr.js",
"src/assets/scripts/g.js"
]
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"serviceWorker": true
},
"development": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": true,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"serviceWorker": true
},
"site-dev": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.site-dev.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"serviceWorker": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "site:build"
},
"configurations": {
"production": {
"browserTarget": "site:build:production"
}
}
},
"server": {
"builder": "@angular-devkit/build-angular:server",
"options": {
"outputPath": "dist/server",
"main": "src/main.server.ts",
"tsConfig": "src/tsconfig.server.json"
},
"configurations": {
"site-dev": {
"fileReplacements": [{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.site-dev.ts"
}]
},
"development": {
"fileReplacements": [{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.dev.ts"
}]
},
"production": {
"fileReplacements": [{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}]
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "site:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"src/_variables.scss",
"src/_shared.scss",
"src/styles.scss"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets",
"src/manifest.json"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"site-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "site:serve"
},
"configurations": {
"production": {
"devServerTarget": "site:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "site"
}
ng add @nguniversal/express-engine