nvm: unnecessary system node required to get past prefix error on clean install

As mentioned in https://github.com/creationix/nvm/issues/1102#issuecomment-250951849, when running nvm install (after sourcing the nvm.sh script with the --no-use flag) from a project with an .nvmrc file, I’m running into the nvm is not compatible with the npm config "prefix" option: currently set to "" error on a clean image unless a system node is available.

For context, this is for a docker image to be used as a Jenkins agent for building node projects. However, to distill it down a bit more, this is an alpine linux docker image based on openjdk:8-jdk-alpine with minimal additional installations, mostly dependencies of being a Jenkins agent.

No .npmrc is being added outside of the project being built by Jenkins and the .npmrc for the project only contains save-exact=true. Environment variables are only being set for Jenkins specific config and $NVM_DIR.

As soon as nodejs is added to the busybox apk add list, nvm install completes successfully without the prefix error, but this system level node installation should be unnecessary since nvm should be responsible for making node and npm available to the Jenkins build.

To make matters worse, the prefix failure from the nvm install command exits with a zero status code, so further commands chained with && are successfully triggered but fail because npm was not made available. This certainly complicated tracking down the problem because the prefix error appeared to only be a warning. If the prefix error is enough to not make npm or node available, the nvm install command should not exit with 0.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 29 (12 by maintainers)

Most upvoted comments

Sure thing. Hopefully some of this will help the next guy at least 😃

Thanks for the help along the way.

i was able to add the coreutils package to the alpine image to make a POSIX compliant ls available, but the other messages remain:

N/A: version "N/A" is not yet installed.
You need to run "nvm install N/A" to install it before using it.

Theres a lot here, so hopefully some of it will be helpful (too long to include directly in the comment, so included as a file):

output.txt

Sorry for the miscommunication. nvm install node should create them. I’m looking for the output of nvm install node ; nvm version node ; set -x ; nvm use node

I have not tracked down the output that you asked for, but wanted to share something else that I realized.

This should probably have been obvious, but since the nvm install command exits with zero and the next step continues, I assumed that the presence of the system node allowed nvm to get past the prefix error. This assumption was not correct. nvm still fails to make the desired version of node/npm available, but the next command continues, using that system node installation.

You may have recognized this, but it did confuse me. Beyond getting us on the right track for the issue at hand, it does further highlight the need for that exit code to be non-zero.

I’m still working on getting to a state where I can get the other output. Stay tuned for that.