Nvm: Cannot use nvm in Makefile

Created on 22 Mar 2017  Â·  6Comments  Â·  Source: nvm-sh/nvm

Is it possible to use nvm inside of a Makefile? The only thing that Google surfaced for me is a throwaway comment on closed issue https://github.com/creationix/nvm/issues/542 saying that it wasn't possible.

Most helpful comment

Figured it out:

node_modules/.yarn-integrity:
    bash -l -c 'nvm exec $(NODE_VERSION) yarn'

Hopefully this has enough Google juice to help the next guy.

All 6 comments

Figured it out:

node_modules/.yarn-integrity:
    bash -l -c 'nvm exec $(NODE_VERSION) yarn'

Hopefully this has enough Google juice to help the next guy.

Indeed, invoking a login shell is the proper way to do this :-)

Still does not work if you want to setup "parent" shell with make. Also it's absolute pain if you have multiple targets depending on nodejs. 😢

I got same problem with this.
/bin/bash: nvm: command not found
from makefile

for anyone coming here in the future and having trouble: to use the solution above (with bash -l for a login shell), the nvm source lines need to be in .bash_profile, not .bashrc (as per https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc)

Invoking source $(HOME)/.nvm/nvm.sh ;\ for me before calling normally nvm use ... works better for me

Was this page helpful?
0 / 5 - 0 ratings