1

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:

module.js:340
    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(https://github.com/creationix/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

latvian
  • 3,161
  • 9
  • 33
  • 62

3 Answers3

1

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

1

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?

latvian
  • 3,161
  • 9
  • 33
  • 62
  • You're right about case sensitivity. It can be considered a bug, but at the same time, can be considered something that a developer just be aware about. Fixing it in the core would probably add overhead for every single file (on OS X), because it would need to check for each file it requires if the case matches exactly. – Myrne Stol May 17 '13 at 21:14
  • Put differently, the case-insensitivity can be considered a "feature" on OS X. :) – Myrne Stol May 17 '13 at 21:15
  • http://stackoverflow.com/questions/13617863/can-i-force-node-js-require-to-be-case-sensitive - this guy has written a validation module for it. – Myrne Stol May 17 '13 at 21:16
  • A quick search in joyent/node only gives https://github.com/joyent/node/issues/2621 . If you feel strongly that it should be fixed in some way, you could report an issue. Maybe the feature for forcing case sensitivity on OS X (my preferred solution, if any) could be put behind a flag. Still, it's a significant change tot the module system and Isaacs is very conservative about it. – Myrne Stol May 17 '13 at 21:25
  • Thank you Meryn.....as long as the initiative is aware of this, i am in peace that i have done my little part:) While I believe it's inappropriate for me to comment, allow me just share that coming from different framework/language, I feel it would be considered a bug, but again...this is a different ecosystem with its own view on life and nothing wrong with it...contrary, its good for innovation – latvian May 17 '13 at 22:31
  • do you know a platform which actually has a remedy for this? If so, which? i.e. I wouldn't know how PHP, Python, Ruby do it. – Myrne Stol May 17 '13 at 22:34
0

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