sdelements / lets-chat

Self-hosted chat app for small teams
http://sdelements.github.io/lets-chat
MIT License
9.77k stars 1.58k forks source link

require-tree has wrong argument (Cannot read property 'findById' of undefined) #656

Closed yzaguirre closed 8 years ago

yzaguirre commented 8 years ago

Since I've updated from 0.4.2 to 0.4.5, every time a user successfully login I get the following error:

/home/chat/lets-chat/app/controllers/presence.js:29
        User.findById(userId, function (err, user) {
            ^
TypeError: Cannot read property 'findById' of undefined
    at Namespace.<anonymous> (/opt/lets-chat/app/controllers/presence.js:29:13)
    at Namespace.emit (events.js:129:20)
    at Namespace.emit (/opt/lets-chat/node_modules/express.oi/node_modules/socket.io/lib/namespace.js:205:10)
    at /opt/lets-chat/node_modules/express.oi/node_modules/socket.io/lib/namespace.js:172:14
    at process._tickCallback (node.js:355:11)

Upon taking my afternoon inspecting code, I caught the require-tree package not loading any of the three (3) directories: models, middlewares and controllers.

After taking some minutes of research I decided to edit app.js:33 as follows:

    models = all(__dirname+'/app/models'),
    middlewares = all(__dirname+'/app/middlewares'),
    controllers = all(__dirname+'/app/controllers'),

Which apparently fixes this mess :)

Some info:

Edit: wrong lines of code