Is there any way how to run “nvm use” automatically in “prestart” npm script?

和自甴很熟 提交于 2019-11-30 09:08:43

Generally on a Mac, the nvm.sh file is located in your home path. Use the $HOME variable if you have multiple Mac users working on the code.

"scripts": {
    "prestart": "source $HOME/.nvm/nvm.sh; nvm use"
}

I would've added this as a comment to the above response, but I'm not allowed :(

Your package.json could look like

"scripts": {
"start": "source /whereever/located/nvm.sh; nvm use; nodemon index.js"
}

To explain. The "start" line is a single shell instance. So you have to have nvm initialize the PATH in that shell instance. Also, nvm is a shell function not an executable shell script. The nvm function lives in the shell instance, and is created by sourcing the nvm.sh file.

Sorry for the edits cuz I didn't test my first two.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!