인프런 커뮤니티 질문&답변
Cannot read property 'length' of null
작성
·
430
0
C:\Users\SE JUN\Desktop\Node.js\gif-chat\views\main.pug:15 13| th 방장 14| tbody > 15| for room in rooms 16| tr(data-id=room._id) 17| td= room.title 18| td= room.password ? '비밀방' : '공개방' Cannot read property 'length' of null
TypeError: C:\Users\SE JUN\Desktop\Node.js\gif-chat\views\main.pug:15
13| th 방장
14| tbody
> 15| for room in rooms
16| tr(data-id=room._id)
17| td= room.title
18| td= room.password ? '비밀방' : '공개방'
Cannot read property 'length' of null
at eval (eval at wrap (C:\Users\SE JUN\Desktop\Node.js\gif-chat\node_modules\pug-runtime\wrap.js:6:10), <anonymous>:58:32)
at eval (eval at wrap (C:\Users\SE JUN\Desktop\Node.js\gif-chat\node_modules\pug-runtime\wrap.js:6:10), <anonymous>:121:4)
at template (eval at wrap (C:\Users\SE JUN\Desktop\Node.js\gif-chat\node_modules\pug-runtime\wrap.js:6:10), <anonymous>:321:99)
at Object.exports.renderFile (C:\Users\SE JUN\Desktop\Node.js\gif-chat\node_modules\pug\lib\index.js:427:38)
at Object.exports.renderFile (C:\Users\SE JUN\Desktop\Node.js\gif-chat\node_modules\pug\lib\index.js:417:21)
at View.exports.__express [as engine] (C:\Users\SE JUN\Desktop\Node.js\gif-chat\node_modules\pug\lib\index.js:464:11)
at View.render (C:\Users\SE JUN\Desktop\Node.js\gif-chat\node_modules\express\lib\view.js:135:8)
at tryRender (C:\Users\SE JUN\Desktop\Node.js\gif-chat\node_modules\express\lib\application.js:640:10)
at Function.render (C:\Users\SE JUN\Desktop\Node.js\gif-chat\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (C:\Users\SE JUN\Desktop\Node.js\gif-chat\node_modules\express\lib\response.js:1012:7)
at C:\Users\SE JUN\Desktop\Node.js\gif-chat\routes\index.js:11:9
at processTicksAndRejections (internal/process/task_queues.js:94:5)
여기서 왜 이런 에러가 뜰까요...?
검색해도 뭐가 문제인지 감이 안잡힙니다.ㅜㅜ
답변 2
0
0
둥치탁치
질문자
router.get('/', async (req, res, next) => {
try {
const rooms = await Room.findOne({});
res.render('main', { rooms, title: 'GIF 채팅방', error: req.flash('roomError') });
} catch (error) {
console.error(error);
next(error);
}
});
routes/index.js에서 에러잡히는 부분입니다





