-
-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sourcing nvm.sh exits with code 3 when .nvmrc is present and version is not installed #1985
Comments
The issue template does not work well with the details.. I tried to fix it but I failed. |
Note that nvm is not supported with homebrew - if you brew uninstall it, and install it the proper way (in the readme), do you see the same behavior? |
Thanks for the The exit code
One possibility is, could you edit |
brew or manual, both give me this exit code. |
that's a good idea. I'll try that tomorrow morning since I'm on my phone now. Is there a reason actually that it returns the same number Ina few places? why not use different numbers for different places and different errors by default? |
Typically I use unique numbers for each code path; but as nvm has gotten more complex, they've blurred together a bit. It would be a reasonable (but technically breaking) change to make sure every exit code in the app is unique (at least for things more complex than simple 0/1 predicates). |
Hm, ok on my home macbook its 0 exit even with a freshly installed one. That's good. Then I'll check tomorrow at work with the problematic machine, and see what could be the issue. |
Thanks for your efforts! I’m looking forward to fixing this, and perhaps convincing me it’s time for unique exit codes :-D |
I found the reproducible way! With nvm not in the system, uninstalled, cleared etc, no rc files, no nodes installed, try this:
Basically, the problem here is sourcing nvm in a dir that has a I don't know how this should be handled. I am basically trying to setup a project with ci, and in the ci I am already in the dir, and I install nvm, then source nvm, then nvm install, then nvm use. This order would work if sourcing would not try to do nvm use inside it I'm guessing. What do you think? |
Interesting. You can source with (I'd expect |
I'll try it. Well, if the ci is using a node image, usually nvm is there already. If it's booting a macos image though, nvm is probably missing, so the init happens, cds in my project and then I get control, when I would start installing nvm and other things that I need. |
This might be due to a bug in bash 3 (which ships on Macs) which makes |
To be honest, I switched to nodenv since last month. Feel free to keep this issue open to solve this if it's still a problem, or close it if you feel it's not relevant anymore. nvm, thank you for your service :D |
Sorry to hear that :-) I believe I've solved it with 58d0933, so I'll close. |
I will try master out of curiosity :D |
@ljharb I just tested on Cheers! |
@JoseLion is this the same setup, then? Circle is sourcing nvm after cd-ing into the project’s directory, and before running |
I'm not sure I understand why CircleCI's image could fix it 😅 jobs:
build-web:
working_directory: ~/repo/web
docker:
- image: cimg/base:stable
steps:
- checkout:
path: ~/repo
- run:
name: Install NodeJS
command: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
source $BASH_ENV
nvm install
nvm alias default
echo 'nvm use default &>/dev/null' >> $BASH_ENV Any Also, it would be harder to for the Official Node Orb to use this workaround since it would have to check the working directory for a I really hope this helps to clarify the issue, NVM is a great tool and the |
Right - the issue is that nvm expects that if an .nvmrc file is present with a node version in it, that before cd-ing into that directory, you'd source nvm. So, in your case, you can change to this: command: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --install' >> $BASH_ENV
source $BASH_ENV (note that |
@ljharb got you, that makes sense! I used Do you think it would be possible to add a fix for this? Probably ignoring the |
It would break other features, unfortunately :-/ specifically, the feature to auto-use the nvmrc version at source time, which in non-CI use cases, is already installed. There may be a way to either detect CI, and do something different; or, only when sourcing nvm.sh, avoid failing when an nvmrc version is not present. |
That would be awesome! Thanks 🙂 🎉 |
I’m experiencing this issue in our Platform.sh configuration. Here’s what we’re running (following the most recently-suggested solution above): hooks:
build: |
set -e
unset NPM_CONFIG_PREFIX
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.38.0/install.sh | dash
# Add required environment variables to profile.
echo 'export NVM_DIR="$PLATFORM_APP_DIR/.nvm"' >> $PLATFORM_APP_DIR/.profile
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --install' >> $PLATFORM_APP_DIR/.profile
# Source profile.
. $PLATFORM_APP_DIR/.profile
nvm current
# TODO: Specifying the version should not be necessary, but Platform
# builds fail without a specific version.
nvm install
nvm use
nvm install-latest-npm (Note that in Platform.sh environments, nvm is exiting with 3. What am I missing? |
i ran into this problem on CircleCI when trying to source the
edit: looks like this didn't fix it after all... |
#1985 (comment) remains my position; a PR to improve the error message would be much appreciated. |
it turns out my fix (defining NVM_DIR before sourcing nvm.sh) didn't actually fix it...
that option is being set by circleci when executing the build. more philosophically, it seems pretty counterintuitive that the a helpful error message would spare debugging time but it still requires the user to jump through weird hoops to get it to work. if there is already a command line option ( as it stands, the |
You can unset it in your circle config, no? I completely agree that a helpful error message isn't as good as improving the core problem, but it's a start. The default behavior is "use", the optional behavior is "install". Both (must) read I think the action items here are initially to improve the error message. After that is completed, it's worth considering some of these options:
|
i tried adding
|
ah, the |
Still running into this issue with v0.39.4. My workaround is to rename .nvmrc, source nvm, then rename back. This is my Makefile target:
|
@omarrelativity you can source it with |
I tried both options already, still get Error 3:
|
and you have |
I'm not sure what is set, I'm running this in a simple $SHELLOPTS shows Doing |
@omarrelativity i think this warrants a separate issue, since those sourcing options should work. mind filing it? |
Issue created #3177 |
I encountered this and under the same conditions I also reproduced #1769, so I think these issues are related, maybe duplicates depending on the root cause. |
Still encountering this while trying to install NVM in a Dockerfile based on Debian bullseye. |
I experimented the same issue when i needed to use My first attempt was: stage('Install Node.js') {
steps {
script {
sh '''
[ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh" --install
'''
}
}
} InvestigationAfter digging i found:
ReproductionI can reproduce the issue with the following steps:
WorkaroundI changed the shell used to run my Jenkins step with bash and it works: stage('Install Node.js') {
steps {
script {
sh '''#!/bin/bash -xe
[ -s "$NVM_DIR/nvm.sh" ] && \\. "$NVM_DIR/nvm.sh" --install
'''
}
}
} BTW, I tried the workaround of temporarily renaming |
When I source
nvm.sh
like. "$HOME/.nvm/nvm.sh"
for manual install and like. $(brew --prefix nvm)/nvm.sh
, the exit code is3
.Even though nvm works after that, in bash scripts with
set -e
, the script stops there, since the command exits with a non-zero value.Is there a reason this fails?
Is there a reason it exits with
3
, if it's not an actual failure?What can we do about that?
Some extra info:
output of
. nvm.sh
withset -x
for "tracing":https://pastebin.com/raw/1Tk9UUsp
Operating system and version: macOS 10.14.2 (mojave)
nvm debug
output:Details
nvm ls
output:Details
How did you install
nvm
? (e.g. install script in readme, Homebrew):Tried both. I mostly do from brew though, since it's easier.
What steps did you perform?
source the file
What happened?
worked, but exits with non-zero value
What did you expect to happen?
to exit with a 0 value since everything seemingly went well
Is there anything in any of your profile files (
.bashrc
,.bash_profile
,.zshrc
, etc) that modifies thePATH
?I ran this without any $PATH alterations. In general I don't have anything in there that touch nvm. Only to include
brew
stuff.The text was updated successfully, but these errors were encountered: