Some modules cannot be found when installed globally.
Say I have:
C:\Users\me\AppData\Roaming\npm
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
When I am at a folder that does not have local modules (e.g. C:\Users\me):
C:\Users\me> node
> require('jspm')
-> jspm;
> require('karma');
-> karma;
> require('jspm-p4');
-> Cannot find module (Error)
> require('npm-check-updates')
-> Cannot find module (Error)
Adding NODE_PATH explicitly pointing to C:\Users\me\AppData\Roaming\npm\npm_modules solves the problem, but that would consider as a workaround instead of a solution as some modules are working while others not.
Referencing original issue:
https://github.com/jspm/jspm-cli/issues/1284
jspm-p4 is a module that I created and you can find it here
Could be related to https://github.com/nodejs/node/issues/3606 but with more info on windows.
@unional I'm not sure I follow your use case. To install a module globally doesn't means that you should be able to require it from any directory. If you install a module globally is to reference them, generally, as CLIs. That's what I read from https://github.com/npm/npm/issues/10422, your require('jspm') shouldn't work and is not the expected behavior.
@a0viedo is right here. Installing a module globally should really only be done for modules that provide command-line scripts/binaries, such as express-generator which provides a command-line script for creating an Express skeleton project.
If you want to install something that you want to get at with require(), don't install it globally (-g).
As it is per design, I'm closing this issue. Thank!
I also figured out how to do what I need to do for jspm. :)
Even though @a0viedo is correct about the usage of globally installed should be used for command line tools. However, if you read the node.js documentation about Loading from the global folders.
NODE_PATH is optional. Node.js should be able to search different locations and locate the dependent modules
But I wonder if these is something wrong about the locations they search.
On Linux instead of $PREFIX/lib/node they should search $PREFIX/lib/node_modules
On windows (which is a bit odd as always) $PREFIX/node_modules,
Then this should work.
Agree with @smartmouse, fixing $PREFIX/node_modules would solve the problem here, as $PREFIX/lib/node would not apply in windows environment.
Most helpful comment
@a0viedo is right here. Installing a module globally should really only be done for modules that provide command-line scripts/binaries, such as
express-generatorwhich provides a command-line script for creating an Express skeleton project.If you want to install something that you want to get at with
require(), don't install it globally (-g).