Skip to content

Conversation

@Deco
Copy link

@Deco Deco commented Nov 1, 2025

When calling nvm run from a bash script that has "Treat unset variables as an error when substituting." set using set -u, it triggers an unbound variable error:

Found '/home/user/path/.nvmrc' with version <23.11.1>
/home/user/.nvm/nvm.sh: line 4017: NVM_IOJS: unbound variable

Setting the variable to false by default fixes this issue.

Test:

minimal_test_for_nvm_bug() {
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    echo "23.11.1" > .nvmrc
    set -u
    nvm run node -e 'console.log("NVM Test Successful")'
}

minimal_test_for_nvm_bug

Notes: Tests not run. No AI used in this PR (except for AI line-completion while editing, which surely everyone uses by now).

When calling nvm from a bash script that has "Treat unset variables as an error when substituting." set using `set -u`, it triggers an unbound variable error:

```
Found '/home/user/path/.nvmrc' with version <23.11.1>
/home/user/.nvm/nvm.sh: line 4017: NVM_IOJS: unbound variable
```

Setting the variable to false by default fixes this issue.

Test:
```bash
minimal_test_for_nvm_bug() {
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    echo "23.11.1" > .nvmrc
    set -u
    nvm run node -e 'console.log("NVM Test Successful")'
}

minimal_test_for_nvm_bug
```
fi

local NVM_IOJS
local NVM_IOJS=false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local NVM_IOJS=false
local NVM_IOJS
NVM_IOJS=false

this is necessary for ksh, which doesn't support local

@Deco
Copy link
Author

Deco commented Nov 4, 2025

Thank you very much for the suggestion, @ljharb .

I don't have time to rebase and retest this pull request (which I know is part of the contribution requirements), so I'm just going to close it.

Also, the issue can be worked around by wrapping the call to nvm with set +u and set -u.

Sorry for the noise.

@Deco Deco closed this Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants