nvm-sh / nvm

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

Your user’s .npmrc file (${HOME}/.npmrc) has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm. #2340

Closed dougouverson closed 3 years ago

dougouverson commented 3 years ago

Operating system and version:

nvm debug output:

```sh nvm --version: v0.37.0 $TERM_PROGRAM: iTerm.app $SHELL: /bin/zsh $SHLVL: 1 whoami: 'dougouverson' ${HOME}: /Users/dougouverson ${NVM_DIR}: '${HOME}/.nvm' ${PATH}: ${NVM_DIR}/versions/node/v15.1.0/bin:./node_modules/.bin:${HOME}/.npm/bin:${HOME}/.pyenv/plugins/pyenv-virtualenv/shims:${HOME}/.pyenv/shims:${HOME}/.pyenv/bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:${HOME}/Dropbox/learning/nand2tetris/tools $PREFIX: '' ${NPM_CONFIG_PREFIX}: '' $NVM_NODEJS_ORG_MIRROR: '' $NVM_IOJS_ORG_MIRROR: '' shell version: 'zsh 5.7.1 (x86_64-apple-darwin19.0)' uname -a: 'Darwin 19.6.0 Darwin Kernel Version 19.6.0: Thu Oct 29 22:56:45 PDT 2020; root:xnu-6153.141.2.2~1/RELEASE_X86_64 x86_64' checksum binary: 'shasum' OS version: Mac 10.15.7 19H15 curl: /usr/bin/curl, curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2 wget: /usr/local/bin/wget, GNU Wget 1.20.3 built on darwin19.0.0. sed: /usr/bin/sed cut: /usr/bin/cut basename: /usr/bin/basename rm: rm: aliased to rm -rf (rm -rf) mkdir: /bin/mkdir xargs: /usr/bin/xargs git: /usr/local/bin/git, git version 2.29.2 ls: grep:: No such file or directory grep: grep: aliased to grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} (grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}), grep (BSD grep) 2.5.1-FreeBSD awk: /usr/bin/awk, awk version 20070501 nvm current: v15.1.0 which node: ${NVM_DIR}/versions/node/v15.1.0/bin/node which iojs: iojs not found which npm: ${NVM_DIR}/versions/node/v15.1.0/bin/npm npm config get prefix: ${HOME}/.npm npm root -g: ${HOME}/.npm/lib/node_modules ```

nvm ls output:

```sh -> v15.1.0 system default -> node (-> v15.1.0) node -> stable (-> v15.1.0) (default) stable -> 15.1 (-> v15.1.0) (default) iojs -> N/A (default) unstable -> N/A (default) lts/* -> lts/fermium (-> N/A) lts/argon -> v4.9.1 (-> N/A) lts/boron -> v6.17.1 (-> N/A) lts/carbon -> v8.17.0 (-> N/A) lts/dubnium -> v10.23.0 (-> N/A) lts/erbium -> v12.19.0 (-> N/A) lts/fermium -> v14.15.0 (-> N/A) ```

How did you install nvm?

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash

What steps did you perform?

Ran commands to install and use node nvm install node nvm use node

What happened?

It seems that nvm did in fact install v15.1.0 but I'm also getting this error message every time I open a new terminal window:

Your user’s .npmrc file (${HOME}/.npmrc) has a globalconfig and/or a prefix setting, which are incompatible with nvm. Run nvm use --delete-prefix v15.1.0 --silent to unset it.

What did you expect to happen?

Not to get an error message.

I did run nvm use --delete-prefix v15.1.0 --silent but this did not fix.

I did shut down iTerm and restarted - only to get error message.

One thing I did notice: I opened .npmrc and see there is one line:

prefix=/Users/dougouverson/.npm

Just to see what would happen, I deleted this line > saved file > exited and opened iTerm. No change.

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

Not that I'm aware of. zsh is now the default shell on macOS 10.15.7

ljharb commented 3 years ago

Deleting that line in .npmrc should indeed have fixed it (it shouldn't be there at all).

You're saying that nvm use --delete-prefix v15.1.0 still doesn't work after that? What code does it exit with (echo $?)?

ljharb commented 3 years ago

Also, what does npm config get prefix and which node print out when you're using your system node?

dougouverson commented 3 years ago

$ nvm use --delete-prefix v15.1.0 --silent $ echo $? 0

$ npm config get prefix /Users/dougouverson/.nvm/versions/node/v15.1.0

$ cat .npmrc prefix=/Users/dougouverson/.npm

How can I figure out what program/script keeps writing to .npmrc?

ljharb commented 3 years ago

I’m afraid that’s something i cant help you with :-/ you might have a npm config set prefix command somewhere, or just be appending to the file directly.

You could try changing the permissions on npmrc so nothing can write to it, and see what errors?

I’m going to close this for now, since the issue isn’t with nvm, just with whatever’s setting your “prefix” setting.

dougouverson commented 3 years ago

This is disappointing. Where am I to go to get help fixing an NVM issue if not in the NVM issue desk?

You say the issue isn't with NVM, and that may be the case. But, this is the second time I've had this issue with getting Node environment set up on macOS, and the only thing in common was NVM.

What else could it be?

Or maybe you could point me in a direction where I could get help.

Thanks so much.

dougouverson commented 3 years ago

And I don't think my issue was "invalid" - humbly!

ljharb commented 3 years ago

Sorry if I was unclear :-) I'm happy to keep trying to help! However, i don't think there's anything i can fix in nvm about it, since nvm is incompatible with the "prefix" setting.

As for "invalid", you're right, that's probably not the best label name - it just means "not a problem with nvm". I'll rename the label slightly.

ljharb commented 3 years ago

Can you share the content of your profile files? (with any sensitive info redacted)

ljharb commented 3 years ago

Can you share the contents of .zprofile and .zshrc?

dougouverson commented 3 years ago

Everything seems to working fine now.

I was able to remove the .npmrc and nothing is writing it again. I'm not sure what script/program created .npmrc in the first place?

Question:

I noticed that when I quit and restart terminal that node version reverts to default (in my case v12.19.0)

Is this normal behavior?

ljharb commented 3 years ago

Glad to hear it!

Yes, that’s expected. You can change the default with nvm alias default, or remove it with nvm unalias default.

dougouverson commented 3 years ago

Thanks so much for hanging in there with me!

vaniadimova commented 3 years ago

Honestly, can't wait for the day when we will have a productive day of coding, the complexity of elements involved in Node is more of politics than a necessity, never mind dealing with MacOs changes and updates that are actually needed. It feels like a war zone and we are in the middle of it. And yes, as dougouerson pointed out the solution is never in one place. Like you guys never used the software before ...vim got nothing to do with it. Who says that everything is connected in the system and this is why we seek to advise. Only if Node people can put their instructions in one place instead of throwing a bug at us and we have to deal with it. I do more debugging than coding, and coding in React is pretty straight forward, few things to watch out for ... just saying it shoudn't be that hard to assist others.

Knogobert commented 2 years ago

Had the same issue as above. Thanks for telling us to check .zshrc @ljharb!

Solved it by commenting out/removing the line in there that said

npm set prefix ~/.npm;

Which was clearly creating it everytime I opened up a new terminal. You can then safely remove the .npmrc if you're not using it for anything else than that prefix.

Mohitp98 commented 2 years ago

Had the same issue after installing nvm on ubuntu with ZSH

Solved it by simply running the mentioned command:

nvm use --delete-prefix v12.22.10 --silent

CodeGetters commented 8 months ago

I think the reason why I use prefix is because it can put all the global dependencies into the directory I specify, but now it is not compatible with prefix in nvm, so how do I set the global dependencies into the directory I specify?🤔🤔🤔

ljharb commented 8 months ago

@CodeGetters that's not a good thing to do, though, so the answer is "you don't". Global deps must never be shared across node versions anyways.

CodeGetters commented 8 months ago

@CodeGetters that's not a good thing to do, though, so the answer is "you don't". Global deps must never be shared across node versions anyways.

I have thought about the advantages and disadvantages according to your answer and found the use I used before, focusing on quick use and not paying attention to the problems it may cause. Thank you very much for your answer!😉