Require cannot find custom module after moving to server


I am trying to deploy a node app that runs fine on my local Mac Lion, however. On the virtual Ubuntu box, it is giving an error:

    throw err;
Error: Cannot find module '../lib/review'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/websites/Node_apps/min-driver-node/routes/reviews.js:2:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)

There is my own custom modules in ./lib folder that are 'require' from the routes as following:

var Review = require('../lib/review');

What have I tried?

  1. Ensured the same Node.js version running via nvm(
  2. Removed node_modules just to re-install them by running "npm install"

Why is the 'require' unable import the custom modules from 'lib' folder on Server while works on Mac? Thank You

Problem courtesy of: latvian


It looks like the 'require' module is case sensitive on Ubuntu but not on Mac....all my modules in lib folder starts with upper case(i.e. lib/Review.js), but when required in other parts of the code, it is lower case - require('../lib/review'). This is causing issue on Ubuntu but not on Mac lion. By updating the code to 'require('../lib/Review'), solves the problem

Is this a bug and i should be reporting this?

Solution courtesy of: latvian


Try set file permissions chmod -R 744 '../lib/review'

Discussion courtesy of: Pavel Kilin

Try using the complete path to the file instead of using the relative path (../).

Discussion courtesy of: user2392190

This recipe can be found in it's original form on Stack Over Flow.