我只需使用
ng new test-ssr
cd test-ssr
ng add @nguniversal/express-engine --clientProject test-ssr
npm run build:ssr
npm run serve:ssr
当我进入localhost:4000时显示
Error: You must pass in a NgModule or NgModuleFactory to be bootstrapped
at View.engine (C:\Users\rober\ng\test-ssr\dist\server.js:39238:23)
at View.render (C:\Users\rober\ng\test-ssr\dist\server.js:123884:8)
at tryRender (C:\Users\rober\ng\test-ssr\dist\server.js:121592:10)
at Function.render (C:\Users\rober\ng\test-ssr\dist\server.js:121544:3)
at ServerResponse.render (C:\Users\rober\ng\test-ssr\dist\server.js:130425:7)
at C:\Users\rober\ng\test-ssr\dist\server.js:135:9
at Layer.handle [as handle_request] (C:\Users\rober\ng\test-ssr\dist\server.js:123312:5)
at next (C:\Users\rober\ng\test-ssr\dist\server.js:123060:13)
at Route.dispatch (C:\Users\rober\ng\test-ssr\dist\server.js:123035:3)
at Layer.handle [as handle_request] (C:\Users\rober\ng\test-ssr\dist\server.js:123312:5)
使用ng update --all --force
更新了所有依赖项,然后npm i typescript@">=3.1.1 <3.3"
也没有解决任何问题(之前和之后都尝试过)
请注意,运行npm start
并打开localhost:4200仍然可以正常工作
您可以在这里看到我的版本 https://github.com/robertisaacBBN/ng-ssr