gpt4 book ai didi

node.js - 无法使用 @ngtools/webpack 创建 Angular 5 通用服务器应用程序应用程序包

转载 作者:太空宇宙 更新时间:2023-11-04 00:15:35 28 4
gpt4 key购买 nike

我正在尝试使用 Angular 5 和 WebPack 构建一个通用应用程序,而无需使用 cli。

我遇到的问题是我似乎无法让 Express 应用程序正常工作,并且每次访问服务器时都会遇到此错误

Error: You must pass in a NgModule or NgModuleFactory to be bootstrapped
at View.engine (/Volumes/Data/Users/mo/Desktop/ng5-universal-webpack/node_modules/@nguniversal/express-engine/src/main.js:34:23)
at View.render (/Volumes/Data/Users/mo/Desktop/ng5-universal-webpack/node_modules/express/lib/view.js:135:8)
at tryRender (/Volumes/Data/Users/mo/Desktop/ng5-universal-webpack/node_modules/express/lib/application.js:640:10)
at Function.render (/Volumes/Data/Users/mo/Desktop/ng5-universal-webpack/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/Volumes/Data/Users/mo/Desktop/ng5-universal-webpack/node_modules/express/lib/response.js:1008:7)
at /Volumes/Data/Users/mo/Desktop/ng5-universal-webpack/dist/server.js:122:47
at Layer.handle [as handle_request] (/Volumes/Data/Users/mo/Desktop/ng5-universal-webpack/node_modules/express/lib/router/layer.js:95:5)
at next (/Volumes/Data/Users/mo/Desktop/ng5-universal-webpack/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Volumes/Data/Users/mo/Desktop/ng5-universal-webpack/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Volumes/Data/Users/mo/Desktop/ng5-universal-webpack/node_modules/express/lib/router/layer.js:95:5)

我认为问题与 server.ts 使用的服务器应用程序包有关,因为如果我通过控制台注销 AppServerModuleNgFactory,它会显示为未定义。

我尝试使我的服务器配置尽可能与 Angular/universal-starter 存储库中的 CLI 项目生成的配置相匹配,但它只是没有生成服务器可以使用的应用程序包

您可以在 https://github.com/mogusbi/ng5-universal-webpack 找到存储库。克隆它,运行 npm start 并转到 localhost:4000

最佳答案

我最终弄清楚了为什么在深入研究 CLI 源代码的细节后没有生成 ModuleNgFactories,这实际上只是因为 AngularCompilerPlugin 中有一个名为 platform 的未记录选项 - 它需要设置为 1 来生成服务器应用程序包,然后由 express 应用程序中的 ngExpressEngine 使用。

一旦你这样做了,一切都会如你所愿!

我希望其他在没有 CLI 的情况下无法使用同构东西的人会发现这很有帮助

关于node.js - 无法使用 @ngtools/webpack 创建 Angular 5 通用服务器应用程序应用程序包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47243439/

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