TypeError: Cannot read property 'username' of undefined

来源:7-14 session存入redis

言戊戌

2019-08-14

写回答

3回答

CocoIloveu

2023-03-12

//img.mukewang.com/szimg/640dd76909e857a007150195.jpg

我也是出现了相同的情况,是要把getPostDate(req)放在get函数里面,变成链式调用,不然就是同步的,会造成数据的丢失,就会报错

0
0

双越

2019-08-14

看下你 src\router\user.js:32:18 这行,以及其上下文的代码,截图贴出来。

0
0

双越

2019-08-14

具体哪一行报错?

(提醒一下,再提问的时候,尽量把所有报错信息都写上,更多信息有助于更快的定位问题)

0
1
言戊戌
> cross-env NODE_ENV=dev nodemon ./bin/www.js [nodemon] 1.19.1 [nodemon] to restart at any time, enter `rs` [nodemon] watching: *.* [nodemon] starting `node ./bin/www.js` req.sessionId 1565780724588_0.8694839660240226 user组件的req.session是 undefined (node:3804) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'username' of undefined at handleUserRouter (E:\node\blog\src\router\user.js:32:18) at getPostData.then.postData (E:\node\blog\app.js:140:22) at process._tickCallback (internal/process/next_tick.js:68:7) (node:3804) 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:3804) [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.
2019-08-14
共1条回复

Node.js+Express+Koa2+Nest.js 开发服务端

从入门到实战,一站式掌握 Node.js+Express+Koa2

4051 学习 · 2006 问题

查看课程