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)