0

I use zsh as the default command-line shell. I have installed node using nvm.

When I try to install GatsbyJS I get an error

npm i -g gatsby-cli
....
npm ERR! code 127
npm ERR! path /Users/username/~/.nvm/versions/node/v16.0.0/lib/node_modules/gatsby-cli
npm ERR! command failed
npm ERR! command sh -c node scripts/postinstall.js
npm ERR! sh: node: command not found

It seems like gatsby-cli trying to run postinstall.js script with node in sh shell, but it is not available there because my nvm/node declared in .zshrc.

I was able to run nvm and node in sh by creating a .profile file like:

export NVM_DIR="~/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
source ~/.nvm/nvm.sh

export PATH=/usr/local/bin:$PATH

But I need to run source ~/.profile for each sh session, otherwise, it doesn't work. As post-install generates a new sh session I can't force it to use .profile.

I'm not strong in all this shell stuff, so any help appreciated.

(Note: I have no such problems with installing other npm packages e.g. webpack-cli)

  • You should consider filing a bug report with the repo – drum Apr 25 '21 at 21:08
  • I'll give a chance to StackOverflow masters. If there is no my mistake I'll create an issue on github. But Gatsby is a pretty popular package and no-one complains, so it's most likely my fault – Oleksandr Blyzniuk Apr 25 '21 at 21:15

1 Answers1

0

The problem was in nvm installation.

Steps to fix:

  1. Edit .zshrc as mentioned in this answer
  2. Re-install node via nvm