nvm always installs global packages to the latest version

Created on 28 Feb 2019  Â·  2Comments  Â·  Source: nvm-sh/nvm

  • Operating system and version:
    MacOS High Sierra 10.13.6
  • nvm debug output:


    nvm --version: v0.34.0
    $TERM_PROGRAM: Apple_Terminal
    $SHELL: /bin/bash
    $SHELL: /bin/bash
    $SHLVL: 1
    $HOME: /Users/ryan.mcconnell
    $NVM_DIR: '$HOME/.nvm'
    $PATH: $NVM_DIR/versions/node/v11.10.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
    $PREFIX: ''
    $NPM_CONFIG_PREFIX: ''
    $NVM_NODEJS_ORG_MIRROR: ''
    $NVM_IOJS_ORG_MIRROR: ''
    shell version: 'GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)'
    uname -a: 'Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Dec 20 21:47:19 PST 2018; root:xnu-4570.71.22~1/RELEASE_X86_64 x86_64'
    OS version: Mac 10.13.6 17G5019
    curl: /usr/bin/curl, curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0
    wget: not found
    git: /usr/bin/git, git version 2.17.2 (Apple Git-113)
    grep: /usr/bin/grep, grep (BSD grep) 2.5.1-FreeBSD
    awk: /usr/bin/awk, awk version 20070501
    sed: illegal option -- -
    usage: sed script [-Ealn] [-i extension] [file ...]
         sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
    sed: /usr/bin/sed, 
    cut: illegal option -- -
    usage: cut -b list [-n] [file ...]
         cut -c list [file ...]
         cut -f list [-s] [-d delim] [file ...]
    cut: /usr/bin/cut, 
    basename: illegal option -- -
    usage: basename string [suffix]
         basename [-a] [-s suffix] string [...]
    basename: /usr/bin/basename, 
    rm: illegal option -- -
    usage: rm [-f | -i] [-dPRrvW] file ...
         unlink file
    rm: /bin/rm, 
    mkdir: illegal option -- -
    usage: mkdir [-pv] [-m mode] directory ...
    mkdir: /bin/mkdir, 
    xargs: illegal option -- -
    usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
               [-L number] [-n number [-x]] [-P maxprocs] [-s size]
               [utility [argument ...]]
    xargs: /usr/bin/xargs, 
    nvm current: v11.10.0
    which node: $NVM_DIR/versions/node/v11.10.0/bin/node
    which iojs: 
    which npm: $NVM_DIR/versions/node/v11.10.0/bin/npm
    npm config get prefix: $NVM_DIR/versions/node/v11.10.0
    npm root -g: $NVM_DIR/versions/node/v11.10.0/lib/node_modules
    

  • nvm ls output:

sh v11.1.0 v11.9.0 -> v11.10.0 system default -> 11.1.0 (-> v11.1.0) node -> stable (-> v11.10.0) (default) stable -> 11.10 (-> v11.10.0) (default) iojs -> N/A (default) unstable -> N/A (default) lts/* -> lts/dubnium (-> N/A) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.16.0 (-> N/A) lts/carbon -> v8.15.0 (-> N/A) lts/dubnium -> v10.15.1 (-> N/A)

  • How did you install nvm? (e.g. install script in readme, Homebrew):
    install script in readme
  • What steps did you perform?

Load an earlier version of node, e.g. v11.1, using nvm

run npm install prettier -g,

  • What happened?

I enter prettier and I get -bash: prettier: command not found.

If I then switch to v11.10.0, without installing the package again, prettier is available in that version, but still not in the version used to install the package.

This is the case for any package I attempt to install globally, not just prettier. Also not just the case when installing from v11.1, but any version I've tried.

Even if I rm -r 11.10.0 from the node versions inside the .nvm directory and then install from a different version, a v11.10.0 directory is created containing the node_modules directory. The package remains inaccessible from the installing version of node.

I have also tried installing with nvm install 10.6 --reinstall-packages-from=11.10 and nvm reinstall-packages 11.10 after successfully installing the package in 11.10.0.

  • What did you expect to happen?
    The global package to be available on the version of node from which it was installed.

  • Is there anything in any of your profile files (.bashrc, .bash_profile, .zshrc, etc) that modifies the PATH?

.bashrc:
export NVM_DIR="$HOME/.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

.bash_profile:
if [ -f ~/.bashrc ]; then source ~/.bashrc fi

Most helpful comment

A hardcoded value in ~/.npmrc was the issue. I must've set v11.10.0 as the prefix when I was trying to get rid of the prefix warning in the integrated terminal in vscode last week, opening up this can of worms in the process. Removing the prefix line solved it.

Thank you so much.

All 2 comments

There's a few questions here.

Global packages are per node version - they are not shared across them. Which means, you have to use nvm reinstall-packages or nvm install --reinstall-packages-from= or default-packages or manually npm install -g them if you want them available.

As far as "the latest version", the reinstall-packages mechanism preserves the same version number that's installed; and default-packages uses whatever you've specified in that file.

The implication here, however, is that you've got v11.10.0 hardcoded somewhere in your PATH, or in ~/.npmrc, or in your profile files. Is there a chance you've monkeyed a bit with that in your bashrc or bash_profile?

A hardcoded value in ~/.npmrc was the issue. I must've set v11.10.0 as the prefix when I was trying to get rid of the prefix warning in the integrated terminal in vscode last week, opening up this can of worms in the process. Removing the prefix line solved it.

Thank you so much.

Was this page helpful?
0 / 5 - 0 ratings