Closed omnigenous closed 5 months ago
The issue is that npm root -g
is returning the wrong place - specifically, npm config get prefix
should not be returning ${HOME}/.local/share/npm
. Do you have that defined in ~/.npmrc
? If so, remove it.
@ljharb Commented prefix
line from my npm config, now it looks likes this:
#prefix=${XDG_DATA_HOME}/npm # don't use with nvm
cache=${XDG_CACHE_HOME}/npm
init-module=${XDG_CONFIG_HOME}/npm/config/npm-init.js
logs-dir=${XDG_STATE_HOME}/npm/logs
$ echo $(npm root -g)
/usr/lib/node_modules
However npm install -g forever
returns error:
npm error code EACCES
npm error syscall mkdir
npm error path /usr/lib/node_modules/forever
npm error errno -13
npm error Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/forever'
(to be clear, you shouldn't be using prefix
ever with anything; the location for global modules shouldn't be overridden)
when nvm has a node version used, npm root -g
should return a path that's inside $NVM_DIR
. What does npm config get prefix
return?
npm config get prefix
returns /usr
ok, so that's the problem. is there anything relevant in env | grep -i prefix
?
(do note that tmux sets PREFIX
which makes it incompatible with npm)
is there anything relevant in
env | grep -i prefix
?
Nope, only:
PYTHONPYCACHEPREFIX=/home/user/.cache/python
Not using tmux either
and which npm
still prints ${NVM_DIR}/versions/node/v20.14.0/bin/npm
?
Nope, which npm
returns /usr/bin/npm
aha, ok so that's the problem - that's taking precedence over nvm's npm. if you have a system node/npm, either uninstall/remove them, or, make sure that your PATH puts nvm's dirs in front of /usr/bin
This was such a headache and even after multiple attempts over a span of few days I didn't come close to solving this. Ended up burning out and haven't touch node stuff for entire summer.
Just use fnm
so much easier to setup and use, took me couple minute to get it working: https://github.com/Schniz/fnm
yay -S fnm-bin
Add to .zshrc
(or more options: https://github.com/Schniz/fnm#shell-setup)
eval "$(fnm env --use-on-cd --shell zsh)"
Operating system and version:
nvm debug
output:nvm ls
output:How did you install
nvm
?What steps did you perform?
Added following to zsh config:
Tried installing
forever
npm package globally:What happened?
I tried:
What did you expect to happen?
Being able to use
forever
globallyIs there anything in any of your profile files that modifies the
PATH
?