老师你好,第3.7节,加入asyncBootstrap后,server端无法调试通过,报错如下,谢谢!

来源:3-7 服务端渲染优化

慕UI259798

2018-08-19

老师你好,第3.7节,加入asyncBootstrap后,server端无法调试通过,3.7节14分钟之前的课程调试都没有问题,本次报错如下,谢谢!

(node:40547) UnhandledPromiseRejectionWarning: TypeError: asyncBootstrap is not a function

    at getTemplate.then.template (/Applications/XAMPP/xamppfiles/htdocs/stydyreact22/server/util/dev-static.js:49:7)

    at <anonymous>

    at process._tickCallback (internal/process/next_tick.js:188:7)

(node:40547) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:40547) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.




dev-static的代码如下:


module.exports = function (app) {
   app.use('/public',proxy({
       target: 'http://0.0.0.0:5577'
   }))
app.get('*',function (req,res) {
   getTemplate().then(template => {
     const routerContext = {}
     const app = serverBundle(createStoreMap(), routerContext, req.url)

     asyncBootstrap(app).then(() => {
       if(routerContext.url) {
         res.status(302).setHeader('Location',routerContext.url)
         res.end()
         return
       }
       const content = ReactDomServer.renderToString(app)
       res.send(template.replace('<!-- app -->',content))
     })
   })
})
}


写回答

1回答

Jokcy

2018-08-19

asyncBootstrap方法你引入来么?

0
2
Jokcy
回复
慕UI259798
哦,他们可能使用es module进行打包,所以commonjs模块体系需要加default
2018-08-20
共2条回复

React全栈+服务器渲染(ssr)打造社区Webapp

【毕设面试】只会写业务代码?out了,带你学会搭建属于自己的工程!

768 学习 · 414 问题

查看课程