-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Description
- Version: 8.4.0
- Platform: 64-bit (Windows)
- Subsystem: npm
Hi, I try configure Node and NPM to use the same folder for install and load modules for all my project to not unnecessarily duplicate data. I want make this much portable as long as it can be, so don't want set NODE_PATH, just use internal rule or config file inside node root folder (called $PREFIX here).
After some try I see this problems:
Default Node find module from this location (https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders)
Btw. this doc should be correct and put additional info for Windows, where Node use not $HOME but $USERPROFILE env (per https://github.com/nodejs/node/blob/master/lib/module.js#L618).
So in my case I have only one option, use $PREFIX/lib/node to put all module here, but NPM not works like that when we try install module:
-
firstly NPM always make
node_modulesfolder (if not exist), so even if I setprefixinnpmrcfile to my$PREFIX/lib/nodethen Node don't find that module, I must move it manually frome$PREFIX/lib/node/node_modulesto$PREFIX/lib/node. -
secondly, when we not change
prefixin NPM (default is Node folder) and runnpm installcommand in my$PREFIX/lib/nodefolder then NPM install module in$PREFIX/node_modulesfolder because it's default folder when we download and unpack Node (it sit only one module there - NPM). So still I must manually move my shared modules from$PREFIX/node_modulesto$PREFIX/lib/node. Removing this$PREFIX/node_modulesfolder and move NPM to$PREFIX/lib/nodeneeds some work because defaultnpmandnpm.cmduse it (and I'm not sure that after such a change NPM will work properly). -
I can make symlink beetwen
$PREFIX/lib/nodeand$PREFIX/node_modules, but the same story asNODE_PATH, I want make this much portable as long as it can be (try not modyfing anything in system). -
I can put all my project files inside
$PREFIX, so they will get access to$PREFIX/node_modules, but sometimes I want put some projects outside$PREFIXfolder and this is not fit in my case.
I'm wondering why Node don't find module in one additional folder $PREFIX/node_modules as last step or before $PREFIX/lib/node step, so maybe add this somewere here https://github.com/nodejs/node/blob/master/lib/module.js#L633, like:
var paths = [path.resolve(prefixDir, 'node_modules'), path.resolve(prefixDir, 'lib', 'node')];Worth noticing that $PREFIX/node_modules folder is default for NPM when used -g param, so this change will cover default behavior Node and NPM in wider range.