Skip to content
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

Nvm uses system node instead of default #846

Closed
nickhhg opened this issue Oct 20, 2021 · 0 comments · Fixed by #863
Closed

Nvm uses system node instead of default #846

nickhhg opened this issue Oct 20, 2021 · 0 comments · Fixed by #863
Assignees
Labels
Milestone

Comments

@nickhhg
Copy link

nickhhg commented Oct 20, 2021

ISSUE TYPE

  • Bug Report

OS / ENVIRONMENT

  1. Host operating system and version: Windows 10 Pro (Version: 21H1) (Build: 19043.1288)
  2. (Windows only) Native Docker or Docker Toolbox: Docker Desktop v4.1.1
  3. Docker version: (Engine) 20.10.8
  4. Docker Compose version: 1.29.2
  5. (Linux) Is SELinux enabled?: no
  6. What git commit hash are you on?: n/a

SUMMARY

when nvm loads it starts with system node despite the default being set to something else. system node coincidentally happens to be the same version as the default/stable version in nvm.

STEPS TO REPRODUCE

# Currently installed node versions. default is stable v16.3
$ nvm ls
       v14.17.1
        v16.3.0
->       system
default -> node (-> v16.3.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.3.0) (default)
stable -> 16.3 (-> v16.3.0) (default)
lts/* -> lts/fermium (-> v14.17.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.1 (-> N/A)
lts/fermium -> v14.17.1

# current node in use
$ nvm current
system

# system node version
$ nvm ls system
->       system

# current default node version
$ nvm ls default
        v16.3.0

# set default node version to lts v14
$ nvm alias default lts/*
default -> lts/* (-> v14.17.1)

# new default node version
$ nvm ls default
       v14.17.1

# use default node
$ nvm use default
Now using node v14.17.1 (npm v6.14.13)

# current node in use (correct)
$ nvm current
v14.17.1

# restart shell
$ exit
logout

PS > .\shell.bat

# current node in use (should be v14)
$ nvm current
system

# check default node (correct)
$ nvm ls default
       v14.17.1

$ nvm ls
       v14.17.1
        v16.3.0
->       system
default -> lts/* (-> v14.17.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.3.0) (default)
stable -> 16.3 (-> v16.3.0) (default)
lts/* -> lts/fermium (-> v14.17.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.1 (-> N/A)
lts/fermium -> v14.17.1

EXPECTED BEHAVIOUR

After setting the default node version, the default node version should be in use upon restarting the shell

ACTUAL BEHAVIOUR

Upon restarting the shell, nvm uses system node rather than the set default

SOLUTION

According to nvm-sh/nvm#1184 (comment) the issue/solution is the ordering of $PATH exports and sourcing of NVM in shell profiles

If you move the below nvm lines found in .bashrc to be after the other $PATH lines, then it resolves the issue.

export NVM_DIR="/opt/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

I have confirmed that the above resolves the issue.

# relevant lines moved to end of .bashrc
$ tail ~/.bashrc
    for f in /etc/bashrc-devilbox.d/*.sh ; do
        if [ -r "${f}" ]; then
            . "${f}"
        fi
    done
    unset f
fi
export NVM_DIR="/opt/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

# set default node version
$ nvm alias default lts/*
default -> lts/* (-> v14.17.1)

# confirm new default version
$ nvm ls default
       v14.17.1

# current version in use
$ nvm current
system

# use default version
$ nvm use default
Now using node v14.17.1 (npm v6.14.13)

# confirm new default version in use
$ nvm current
v14.17.1

# restart shell
$ exit
logout
PS > .\shell.bat

# confirm version in use is default and not system (correct)
$ nvm current
v14.17.1

@nickhhg nickhhg added the bug label Oct 20, 2021
@cytopia cytopia self-assigned this Feb 1, 2022
@cytopia cytopia added this to the v1.10.2 milestone Feb 1, 2022
@cytopia cytopia mentioned this issue Feb 2, 2022
@cytopia cytopia linked a pull request Feb 2, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants