gpt4 book ai didi

angular - 类型错误 : provideModuleMap is not a function ~ NestJS

转载 作者:搜寻专家 更新时间:2023-10-30 21:32:30 33 4
gpt4 key购买 nike

升级 NestJS 后,我收到以下错误 TypeError: provideModuleMap is not a function。在 Angular 中使用 NestJS 进行服务器端渲染(SSR),结合 Angular Universal 渲染 SSR。

正确工作依赖:

"@nestjs/common": "^6.3.1",
"@nestjs/core": "^6.3.1",
"@nestjs/ng-universal": "^1.2.0",
"@nestjs/platform-express": "^6.3.1"

更新依赖导致错误:

"@nestjs/common": "^6.5.2",
"@nestjs/core": "^6.5.2",
"@nestjs/ng-universal": "^2.0.0",
"@nestjs/platform-express": "^6.5.2"

nguniversal 依赖项(它们不会改变):

"@nguniversal/common": "^8.1.1",
"@nguniversal/express-engine": "^8.1.1",
"@nguniversal/module-map-ngfactory-loader": "^8.1.1",
"express": "^4.17.1",

使用 Angular 8.2.0。其他文件(app.server.module.ts 等)应该没问题,因为使用 SSR 时 SSR 工作得很好。完整的错误日志:

TypeError: provideModuleMap is not a function
at View.app.engine (C:\users\myapp\node_modules\@nestjs\ng-universal\dist\utils\setup-universal.utils.js:23:17)
at View.render (C:\users\myapp\node_modules\express\lib\view.js:135:8)
at tryRender (C:\users\myapp\node_modules\express\lib\application.js:640:10)
at Function.render (C:\users\myapp\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (C:\users\myapp\node_modules\express\lib\response.js:1012:7)
at app.get (C:\users\myapp\node_modules\@nestjs\ng-universal\dist\angular-universal.module.js:60:66)
at Layer.handle [as handle_request] (C:\users\myapp\node_modules\express\lib\router\layer.js:95:5)
at next (C:\users\myapp\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\users\myapp\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\users\myapp\node_modules\express\lib\router\layer.js:95:5)

最佳答案

我无法在 Nest 存储库中找到任何文档,但查看了 AngularUniversalModule 的选项界面,我尝试了这个并让它工作:

import { Module } from '@nestjs/common';
import { AngularUniversalModule, applyDomino } from '@nestjs/ng-universal';
import { join, resolve } from 'path';
import { ngExpressEngine } from '@nguniversal/express-engine';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';

const config = require('config');

// Path to server bundle in dist
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('../../../../dist/server/main');

applyDomino(global, join(resolve(), `${config.Http.distDir}/client/index.html`));

@Module({
imports: [
AngularUniversalModule.forRoot({
// Path to client code in dist
viewsPath: join(resolve(), `${config.Http.distDir}/client`),
bundle: {
AppServerModuleNgFactory,
LAZY_MODULE_MAP,
provideModuleMap,
ngExpressEngine
}
})
],
})
export class CoreModule
{
}

关于angular - 类型错误 : provideModuleMap is not a function ~ NestJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57431624/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com