fish shell and global npm modules

8.8k views Asked by At

I'm experiencing some issues with my local environment.

I'm using:

  • homebrew (1.1.4)
  • fish shell (2.4)
  • n version manager (2.1.0)
  • node
  • npm

All of the above were initially installed via homebrew.

Issues:

  • Any globally installed modules cannot be run.
  • I cannot update npm versions.

The node versions I use regularly are 0.10.48 and 6.9.2 - but mostly 4.6.2.

I've created some aliases in fish to be able to get the the global modules to run. I'd prefer to address the root cause rather than continue applying further bandaids though.

Extra info:

~> npm config get prefix
/Users/me/.npm-packages

~> npm bin
/Users/me/node_modules/.bin

What happens when I try to update npm:

~> npm install -g npm@3
/Users/me/.npm-packages/bin/npm -> /Users/me/.npm-packages/lib/node_modules/npm/bin/npm-cli.js
[email protected] /Users/me/.npm-packages/lib/node_modules/npm
~> npm -v
2.15.9

When I try to call a global module:

~> gulp
fish: Unknown command 'gulp'

What I've tried in order to fix the global modules:

~> cat ~/.config/fish/config.fish
set fish_user_paths /Users/me/.npm-packages

ls ~/.config/fish/functions
bower.fish ember.fish pm2.fish

~> cat ~/.config/fish/functions/bower.fish 
function bower
    /Users/me/.npm-packages/bin/bower  $argv;
end

Any help you can provide will be greatly appreciated! I've been trying to fix this for awhile now without any luck!

5

There are 5 answers

0
kurt343 On BEST ANSWER

I resolved this by completely uninstalling (and deleting any traces of) node, npm and n, uninstalling fish shell and changing to zsh instead.

Afterwards, I installed nvm and used it to restore node on my machine.

Global npm modules now work.

0
cesards On

You can use installed npm modules. You just need to add npm global path to the shell. To do that, I ran:

$ npm config get prefix
// Output: /usr/local/Cellar/node/9.2.1

and then, added to my fish/config.fish:

set PATH /usr/local/Cellar/node/9.2.1/bin $PATH

This is the Github related link that helped me solving the problem.

0
Almokhtar On

For me non of this worked, so i installed oh my fish nvm plugin

omf install nvm
1
LacOniC On

My permanent solution (with macOS Mojave and fish 2.7.1):

set -U fish_user_paths /Users/{USERNAME}/.npm-packages/bin $fish_user_paths

Btw, below one works but only in terminal session:

set PATH $PATH /Users/{USERNAME}/.npm-packages/bin

Note: You can find npm-packages path with:

printf "%s\n" $PATH
0
Joe On

What happens when you install node application globally https://docs.npmjs.com/getting-started/fixing-npm-permissions

Configuring in OSX 10.12.5 with fish v2.6.0 node v8.1.0 example command in terminal returns both

term~> npm install jshint -g
/Users/username/npm-global/lib/node_modules/bin/jshint -> 
/Users/username/npm-global/lib/node_modules/jshint/bin/jshint

the PATH you should have in shell to enable you to execute jshint (installed package) -> pointing to the actual install location

Include line below for configuring PATH in file ~/.profile

export PATH="$HOME/npm-global/lib/node-modules/:$PATH"