I recently installed Node.js on a fresh Linode box, and I think I'm in a weird situation where I can't use require()
to load any third party modules.
I've installed npm
and have successfully installed modules via npm
, but whenever I try to require
one of the modules (or just some of my own code in the same directory), Node.js throws
an error
saying it can't find the module.
Any thoughts as to why this might be happening?
Here's an example error message:
root@li200-141:/home/mike# npm install sequelize npm ERR! sudon't! npm ERR! sudon't! Running npm as root is not recommended! npm ERR! sudon't! Seriously, don't do this! npm ERR! sudon't! npm info it worked if it ends with ok npm info version 0.2.2 npm info fetch http://registry.npmjs.org/sequelize/-/sequelize@0.4.2.tgz npm info install sequelize@0.4.2 npm info activate sequelize@0.4.2 npm info build Success: sequelize@0.4.2 npm ok root@li200-141:/home/mike# node > var n = require('sequelize').Sequelize Error: No such native module sequelize at requireNative (node.js:83:32) at cwdRequire (repl:27:10) at [object Context]:1:9 at Interface.<anonymous> (repl:96:19) at Interface.emit (events:27:15) at Interface._ttyWrite (readline:295:12) at Interface.write (readline:132:30) at Stream.<anonymous> (repl:77:9) at Stream.emit (events:27:15) at IOWatcher.callback (net:489:16)
Apparently, there is a bug in node v0.2.2 that prevents require from working properly from the REPL.
Try putting your code in a .js file instead. That worked for me.