nodeclipse doesn't recognize any module

1.2k views Asked by At

Any require statement that refers to any global module failed. The module is installed globally (-g) and regular node in command line run just fine. redis is failing, mongodb is failing and so on. I didn't find any configuration options for that. express working just fine, but not the other modules.

after sudo npm install -g redis for example, nodeclipse can't find it. the node command line, works fine.

run both with regular user.

2

There are 2 answers

1
Paul Verest On

Have you just 'npm install' those module?

Give more information in your questions, as it is impossible to tell what is different in your environment.

0
waTeim On

Node includes modules differently then maybe one would expect. From the node docs:

If the module identifier passed to require() is not a native module, and does not begin with '/', '../', or './', then node starts at the parent directory of the current module, and adds /node_modules, and attempts to load the module from that location.

If it is not found there, then it moves to the parent directory, and so on, until the root of the tree is reached.

So yes npm does install to a global directory when invoked with the -g option, however that directory is not read from by node unless the current module is also located in that same directory or a subdirectory, which would work so long as that other module is also installed by npm -g.

However, this scheme does not work if the start .js is in some different directory.

So, I think for you to get this to work, add to the NODE_PATH environment variable where npm installed the modules (e.g. NODE_PATH=/usr/local/lib/node_modules). This can be done navigating from Run As ... -> Run Configurations -> Environment Tab