nvm-sh / nvm

Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions
MIT License
79.09k stars 7.92k forks source link

reinstall-packages failed within nvm_cd #2579

Open gabmontes opened 3 years ago

gabmontes commented 3 years ago

Operating system and version:

macOS Big Sur v11.5.2

nvm debug output:

```sh nvm --version: v0.38.0 $TERM_PROGRAM: Apple_Terminal $SHELL: /bin/zsh $SHLVL: 1 whoami: [EDITED] ${HOME}: /Users/[EDITED] ${NVM_DIR}: '${HOME}/.nvm' ${PATH}: ${NVM_DIR}/versions/node/v14.17.6/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Library/Apple/usr/bin $PREFIX: '' ${NPM_CONFIG_PREFIX}: '' $NVM_NODEJS_ORG_MIRROR: '' $NVM_IOJS_ORG_MIRROR: '' shell version: 'zsh 5.8 (x86_64-apple-darwin20.0)' uname -a: 'Darwin 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:31 PDT 2021; root:xnu-7195.141.2~5/RELEASE_X86_64 x86_64' checksum binary: 'shasum' OS version: macOS 11.5.2 20G95 curl: /usr/bin/curl, curl 7.64.1 (x86_64-apple-darwin20.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.41.0 wget: /usr/local/bin/wget, GNU Wget 1.21.1 hecho en darwin20.4.0. sed: /usr/bin/sed cut: /usr/bin/cut basename: /usr/bin/basename rm: rm: aliased to rm -i (rm -i) mkdir: /bin/mkdir xargs: /usr/bin/xargs git: /usr/bin/git, git version 2.30.1 (Apple Git-130) ls: grep:: No such file or directory grep: grep: aliased to grep --color (grep --color), grep (BSD grep) 2.5.1-FreeBSD awk: /usr/bin/awk, awk version 20200816 nvm current: v14.17.6 which node: ${NVM_DIR}/versions/node/v14.17.6/bin/node which iojs: iojs not found which npm: ${NVM_DIR}/versions/node/v14.17.6/bin/npm npm config get prefix: ${NVM_DIR}/versions/node/v14.17.6 npm root -g: ${NVM_DIR}/versions/node/v14.17.6/lib/node_modules ```

nvm ls output:

```sh v8.17.0 v10.23.0 v10.24.1 v12.20.0 v14.15.1 v14.17.1 v14.17.2 v14.17.5 -> v14.17.6 default -> 14 (-> v14.17.6) iojs -> N/A (default) unstable -> N/A (default) node -> stable (-> v14.17.6) (default) stable -> 14.17 (-> v14.17.6) (default) lts/* -> lts/fermium (-> v14.17.6) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.17.0 lts/dubnium -> v10.24.1 lts/erbium -> v12.22.6 (-> N/A) lts/fermium -> v14.17.6 ```

How did you install nvm?

Homebrew

What steps did you perform?

nvm install 14 --reinstall-packages-from=node

What happened?

Downloading and installing node v14.17.6...
Downloading https://nodejs.org/dist/v14.17.6/node-v14.17.6-darwin-x64.tar.xz...
############################################################################################################################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v14.17.6 (npm v6.14.15)
VERSION=''
Reinstalling global packages from v14.17.5...
No installed global packages found...
Linking global packages from v14.17.5...
nvm_cd:cd:1: no such file or directory: /Users/[EDITED]/[VALID_LOCAL_PACKAGE_DIR]\n/Users/[EDITED]/[VALID_LOCAL_PACKAGE_DIR]

What did you expect to happen?

reinstall-packages to work instead of failing as shown above.

As you can see, it failed to parse/split the list of global packages as it is a single string with a /n instead of valid two paths.

Is there anything in any of your profile files that modifies the PATH?

No

ljharb commented 3 years ago

(note: nvm is unsupported when installed via homebrew, as the formula indicates; please brew uninstall it and install it properly with the install script from the readme)

What does npm ls -g --depth=0 print out?

Maciej93 commented 2 years ago

Operating system and version:

macOS Big Sur v11.5.2

nvm debug output:

nvm ls output:

How did you install nvm?

Homebrew

What steps did you perform?

nvm install 14 --reinstall-packages-from=node

What happened?

Downloading and installing node v14.17.6...
Downloading https://nodejs.org/dist/v14.17.6/node-v14.17.6-darwin-x64.tar.xz...
############################################################################################################################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v14.17.6 (npm v6.14.15)
VERSION=''
Reinstalling global packages from v14.17.5...
No installed global packages found...
Linking global packages from v14.17.5...
nvm_cd:cd:1: no such file or directory: /Users/[EDITED]/[VALID_LOCAL_PACKAGE_DIR]\n/Users/[EDITED]/[VALID_LOCAL_PACKAGE_DIR]

What did you expect to happen?

reinstall-packages to work instead of failing as shown above.

As you can see, it failed to parse/split the list of global packages as it is a single string with a /n instead of valid two paths.

Is there anything in any of your profile files that modifies the PATH?

No

ljharb commented 2 years ago

@Maciej93 what version of nvm are you using? If not the latest, please upgrade and try again.

gabmontes commented 2 years ago

@ljharb just tried again to go from v14.17.6 to v16 and had the same problem.

The problem happens with the packages that were npm link'ed from local repositories. The ones installed globally from NPM were properly migrated.

Logs below:

$ nvm install 16 --reinstall-packages-from=node        
Downloading and installing node v16.13.0...
Downloading https://nodejs.org/dist/v16.13.0/node-v16.13.0-darwin-x64.tar.xz...
############################################################################################################################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v16.13.0 (npm v8.1.0)
VERSION=''
Reinstalling global packages from v14.17.6...
[EDITED]
Linking global packages from v14.17.6...
nvm_cd:cd:1: no such file or directory: /Users/[EDITED]/[VALID_LOCAL_DIR_1]\n/Users/[EDITED]/[VALID_LOCAL_DIR_2]

$ npm ls -g --depth=0
/Users/[EDITED]/.nvm/versions/node/v16.13.0/lib
└── npm@8.1.0

$ nvm use 14                                   
Now using node v14.17.6 (npm v6.14.15)

$ npm ls -g --depth=0
/Users/[EDITED]/.nvm/versions/node/v14.17.6/lib
├── [PACKAGE_NAME_1]@1.0.0 -> /Users/[EDITED]/[VALID_LOCAL_DIR_1]
├── [PACKAGE_NAME_2]@1.0.0 -> /Users/[EDITED]/[VALID_LOCAL_DIR_2]
└── npm@6.14.15

$ nvm --version      
0.39.0

Hope this helps. If you need any more information, please let me know. Would be awesome if we can figure this out!

ljharb commented 2 years ago

In node 14, what's the output of nvm_npm_global_modules? Please try to redact as little as you can; specific characters might be important since we're doing string parsing.

gabmontes commented 2 years ago

@ljharb this is the output:

$ npm ls -g --depth=0   
/Users/user/.nvm/versions/node/v14.17.6/lib
├── package-1@2.8.0 -> /Users/user/Documents/package-1
├── package-2@1.0.0 -> /Users/user/Documents/package-2
├── package-3@1.0.1 -> /Users/user/Documents/package-3
├── npm@6.14.15
└── peerflix@0.39.0

$ nvm_npm_global_modules       
No .nvmrc file found
Please see `nvm --help` or https://github.com/nvm-sh/nvm#nvmrc for more information.
 //// 

$ nvm_npm_global_modules 14
peerflix@0.39.0 //// /Users/user/Documents/package-1
/Users/user/Documents/package-2
/Users/user/Documents/package-3

It is edited but believe me, there are no special chars or anything weird.

ljharb commented 2 years ago

What's the output of type -a cd?

gabmontes commented 2 years ago

It is:

$ type -a cd
cd is a shell builtin
cd is /usr/bin/cd
ljharb commented 2 years ago

aha, this is zsh - what's the output of setopt? The stock setopt on my zsh is:

combiningchars
interactive
monitor
shinstdin
zle
gabmontes commented 2 years ago

Yeah! I'm using zsh as described in the output of nvm debug 😄

The output of setopt on mine looks much larger:

$ setopt
alwaystoend
autocd
autopushd
combiningchars
completeinword
extendedhistory
noflowcontrol
histexpiredupsfirst
histignoredups
histignorespace
histverify
interactive
interactivecomments
login
longlistjobs
monitor
promptsubst
pushdignoredups
pushdminus
sharehistory
shinstdin
zle

Do you think any of these may be affecting nvm? My zsh is also almost stock. I only have some plugins enabled:

plugins=(common-aliases docker docker-compose git zsh-autosuggestions)
ljharb commented 2 years ago

Absolutely it might be - what would be great is if you can binary search and try to figure out which option it is (or which plugin, but that's never been an issue before for nvm users).

Once we've narrowed it down, nvm can work around it so you don't have to keep that option disabled.