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_modules
folder (if not exist), so even if I setprefix
innpmrc
file to my$PREFIX/lib/node
then Node don't find that module, I must move it manually frome$PREFIX/lib/node/node_modules
to$PREFIX/lib/node
. -
secondly, when we not change
prefix
in NPM (default is Node folder) and runnpm install
command in my$PREFIX/lib/node
folder then NPM install module in$PREFIX/node_modules
folder 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_modules
to$PREFIX/lib/node
. Removing this$PREFIX/node_modules
folder and move NPM to$PREFIX/lib/node
needs some work because defaultnpm
andnpm.cmd
use it (and I'm not sure that after such a change NPM will work properly). -
I can make symlink beetwen
$PREFIX/lib/node
and$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$PREFIX
folder 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.