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

Why does nvm use have to be run again when installing a package that exists on other version #3218

Open
MichaelGoberling opened this issue Oct 17, 2023 · 8 comments

Comments

@MichaelGoberling
Copy link

[Sorry I removed the issue template because it didn't seem to fit this question]

Background
I installed Node 20 using nvm and then installed a package on Node 20 that I already had on Node 18.

After running npm install -g <package> on Node 20, nvm was still targeting the Node 18 version of the package. Only after running nvm use 20 again did it target the Node 20 version.

Question
I guess I would expect nvm to target the Node 20 version of the package immediately after npm installing it, but it stays on Node 18. Is this expected?

Logs

➜  photoshop-api git:(main) nvm use 20                              <---- Switch to Node 20 
Now using node v20.6.1 (npm v9.8.1)
➜  photoshop-api git:(main) aio --version 
 ›   Warning: @adobe/aio-cli update available from 9.3.0 to 9.4.0.
 ›   Run npm install -g @adobe/aio-cli to update.
@adobe/aio-cli/9.3.0 darwin-arm64 node-v20.6.1
➜  photoshop-api git:(main) which aio 
/Users/mgoberling/.nvm/versions/node/v18.17.1/bin/aio.      <---- Still running Node 18 pkg, which is ok
➜  photoshop-api git:(main) npm i -g @adobe/aio-cli         <---- Install package on Node 20

added 1401 packages in 31s

186 packages are looking for funding
  run `npm fund` for details
➜  photoshop-api git:(main) which aio 
/Users/mgoberling/.nvm/versions/node/v18.17.1/bin/aio        <---- Nvm stays targeting Node 18 pkg
➜  photoshop-api git:(main) aio --version 
 ›   Warning: @adobe/aio-cli update available from 9.3.0 to 9.4.0.
 ›   Run npm install -g @adobe/aio-cli to update.
@adobe/aio-cli/9.3.0 darwin-arm64 node-v20.6.1
➜  photoshop-api git:(main) nvm use 20                               <---- Re-switch to Node 20 
Now using node v20.6.1 (npm v9.8.1)
➜  photoshop-api git:(main) aio --version 
@adobe/aio-cli/9.4.0 darwin-arm64 node-v20.6.1
➜  photoshop-api git:(main) which aio     
/Users/mgoberling/.nvm/versions/node/v20.6.1/bin/aio         <---- Nvm now targeting Node 20 pkg
@ljharb
Copy link
Member

ljharb commented Oct 18, 2023

Still running Node 18 pkg, which is ok

that’s not ok - when you’re using v20, packages installed on v18 should not be available. That suggests that your PATH is incorrect (which may have been revealed by some of the items in the template :-p )

@MichaelGoberling
Copy link
Author

MichaelGoberling commented Oct 18, 2023

Ah sorry about that. Thanks for the explanation

Okay, I'm using zsh and do have a couple things modifying my PATH in ~/.zshrc (Notably Homebrew, pnpm, and Bun.js)

I'll have to check my setup. It seems like every time I run nvm use, the new Node bin path is pre-pended to my PATH. If I nvm use a lot in a shell session my PATH grows very long, i.e:

PATH=/Users/mgoberling/.nvm/versions/node/v20.6.1/bin:/Users/mgoberling/.nvm/versions/node/v18.17.1/bin:
/Users/mgoberling/.nvm/versions/node/v16.20.2/bin:/Users/mgoberling/.nvm/versions/node/v20.6.1/bin:
/Users/mgoberling/.nvm/versions/node/v18.17.1/bin:/Users/mgoberling/.nvm/versions/node/v18.17.1/bin...

@ljharb
Copy link
Member

ljharb commented Oct 18, 2023

What version of nvm are you using? If not the latest, try updating.

@MichaelGoberling
Copy link
Author

Was previously running 0.39.1. Just updated to 0.39.5

@ljharb
Copy link
Member

ljharb commented Oct 18, 2023

Does that fix the PATH issue?

@MichaelGoberling
Copy link
Author

No unfortunately, the PATH var is still growing when I use nvm use. I'm thinking it's something in my .zshrc

@ljharb
Copy link
Member

ljharb commented Oct 19, 2023

Can you share it? If you’re using omz, please share the output of setopt as well.

@hengistchan

This comment was marked as spam.

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

No branches or pull requests

3 participants