Skip to content

Instantly share code, notes, and snippets.

@vhbui02
Last active April 21, 2023 03:37
Show Gist options
  • Save vhbui02/1ebbc69cf735c02cf14664706ff5cb22 to your computer and use it in GitHub Desktop.
Save vhbui02/1ebbc69cf735c02cf14664706ff5cb22 to your computer and use it in GitHub Desktop.
[Some common errors] I've spent so many hours identifying this shjt, DO NOT forget #fish #nvm

At the start of a Fish Shell, by default it doesn't source nvm to preserve speed.

=> By default, $PATH don't have /bin directory /home/darkswordman/.nvm/versions/node/v18.16.0/bin

Common error

Since there are programs, plugins (e.g. plugins in SublimeLinter), sometimes they need to know where node is to run some node command.

Since we only source NVM when we use one of the aliases (function aliases, NOT binary aliases), and these function aliases only exists in Fish Shell.

=> No sourcing nvm before when running outside of Fish Shell.

=> Error occurs: E.g. SublimeLinter, SublimeLinter-eslint SublimeLinter: ERROR: /usr/bin/env: ‘node’: No such file or directory

Solution #1

Since these plugins by default find node binary inside /usr/local/bin/ (maybe, some may look in another directory but this is the common one. If you by any chance are using SublimeLinter, there is a setting called "paths" that make it look for specific directory), we gonna make a binary alias 'node' inside it.

Create a binary alias:

sudo gedit /usr/local/bin/node

Add these command inside: (remember, we are defining "node" binary alias)

#! /usr/bin/env fish

__nvm_run "node" $argv

Make that file executable:

chmod +x /usr/local/bin/node

Test it:

which node

Now when ever you ran node OUTSIDE Fish Shell, you will have the same effect when running INSIDE Fish Shell

Now do it for other plugins (e.g. eslint, prettier, ...) if you wanna type them directly into terminal.

Soluion #2

Specify in this link:

SublimeLinter/SublimeLinter#1318 (comment)

Note: This is NOT recommended since node version change all the time, today you use v18.16.0, tomorrow you use v100.0.0, who knows?

Solution #3

Add this line into config.fish

bass source $NVM_DIR/nvm.sh

NOTE: This is NOT recommended since sourcing nvm everytime you open a new terminal will slow it down by a couple of seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment