3

I have running in my Mac a Node.JS server, and, I access to it from other computer, the server doesn't crash, but, I don't know why, the application crashes when I access from my iPad. If I access from Safari, the server works, but, with Chrome for iPad, the app crash!

This is the error: TypeError: Cannot read property 'following' of null. Why this happens?

EDITED:

app.get('/home', middleware.yeses, function (req, res){

 console.log(req.session.user + "\n\n");

 UserModel.find({ user: req.session.user }, function (err, user){

      console.log(user);

      res.render('home.ejs', {

         username: req.session.user,
         avatar: user[0].avatar,            
         following: user[0].following.length,
         followers: user[0].followers.length

      }); 

  });

});

EDITED:

I changed the console.log(user); to this console.log(user[0].following). And there's no problem. I don't know why, there's a problem with it in the locals.

4

1 回答 1

0

发生这种情况是因为 JavaScript 正在引发异常。在代码中的某处,分配了一个变量,并且正在访问该变量上null的属性。following此操作引发异常。

var obj = null;
obj.following; // exception thrown!

无法为您提供更多帮助。使用您提供的信息和代码(两者都很少)。但是寻找您在哪里访问following属性并从那里进行调试。


更新:

看来user[0]null。为什么?不知道。这取决于您尚未发布的其他代码。在哪里user声明和填充?它是一个数组吗?因为这对于名为user.

于 2013-01-02T19:09:11.797 回答