Closed samholmes closed 11 months ago
I suspect your node-installed homebrew might come with a hardcoded npmrc that sets prefix
. What output and exit codes do you get from the following commands:
nvm_npmrc_bad_news_bears /opt/homebrew/lib/node_modules/npm/npmrc
nvm_npmrc_bad_news_bears /opt/homebrew/etc/npmrc
nvm_npmrc_bad_news_bears $HOME/.npmrc
?
❯ nvm_npmrc_bad_news_bears /opt/homebrew/lib/node_modules/npm/npmrc
zsh: command not found: nvm_npmrc_bad_news_bears
hm, that suggests that zsh isn't even sourcing nvm.sh at all. Can you . $NVM_DIR/nvm.sh
and try again?
@ljharb I did . $NVM_DIR/nvm.sh
and then ran which nvm_npmrc_bad_news_bears
without any avail. I took a peak in the nvm.sh
file and found no reference to nvm_npmrc_bad_news_bears
.
which
won't ever work with nvm, nvm is a bunch of sourced shell functions. After sourcing the file, you should just be able to run it.
which
does work for other shell functions such as nvm_install_latest_npm
(it writes out the function implementation). I ran nvm_npmrc_bad_news_bears
again after sourcing and still got the same results.
ah, that's a zsh-specific behavior then :-) use command -v
to be posix-compliant.
I think the issue is that you're using an ancient version of nvm - v0.36.0. Can you upgrade to v0.39.1?
Upgrading got ride of the "prefix" message, though the default node is still system
from sub-shells. What determines the default node version used?
nvm alias default node
will set it to "node" (ie, the latest available); or, if you have it in a .nvmrc
file in the current directory or any parent directory, its contents will determine it.
If no default alias or nvmrc is available, the default is system
.
While in a sub-shell (running zsh
), nvm ls
shows:
v10.23.0
v12.19.0
v14.15.0
v14.17.5
v16.15.1
-> system
default -> lts/* (-> v16.15.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.15.1) (default)
stable -> 16.15 (-> v16.15.1) (default)
lts/* -> lts/gallium (-> v16.15.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.12 (-> N/A)
lts/fermium -> v14.19.3 (-> N/A)
lts/gallium -> v16.15.1
and running nvm use 16
does not change the selection; which node
prints /opt/homebrew/bin/node
and node --version
prints v18.0.0
.
This is what I have in my .zshrc
file:
# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
No other reference to NVM in .zprofile
or .zenv
. I have no .nvmrc
file.
Sorry for the delay here.
What, specifically, do you have in your profile files that alters the PATH after those nvm lines? In particular, if anything homebrew-related prepends itself to the PATH afterwards, nvm will never be able to take over from homebrew's node.
After NVM_DIR
settings in my .zshrc
:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
This is very confusing. What does env | grep -i prefix
print out?
HOMEBREW_PREFIX=/opt/homebrew
Same print in both regular shell, and sub-shell (i.e. after running zsh
).
aha! the error message above says the "npm config" prefix option. Is there an .npmrc
in your project dir, or in $HOME/.npmrc
?
There is a $HOME/.npmrc
file, but it just contains:
//registry.npmjs.org/:_authToken=***
I did brew uninstall node
and now nvm will always take precedent over "system" because /opt/homebrew/bin
(in the path) does not contain a node
bin
That's certainly a workaround, but nvm should be putting its own directories first in the PATH, and the homebrew ones shouldn't be added after it.
I found this in my .zshrc:
#
# homebrew setup, following https://noahpeeters.de/posts/apple-silicon/homebrew-setup/
#
if [ -d "/opt/homebrew/bin" ]; then
export PATH="/opt/homebrew/bin:$PATH"
fi
function ibrew() {
arch --x86_64 /usr/local/bin/brew $@
}
# variables needed to properly install things under intel or m1
ARCH="$(uname -m)"
case ARCH in
i386) ARCH="386" ;;
i686) ARCH="386" ;;
x86_64) ARCH="amd64" ;;
arm) dpkg --print-architecture | grep -q "arm64" && ARCH="arm64" || ARCH="arm" ;;
esac
# commenting this out removed the error
# if [[ "${ARCH}" == "arm64" ]]; then
# PREFIX="/opt/homebrew"
# else
# PREFIX="/usr/local"
# fi
I think this has been answered.
I got this error with zsh because I load the homebrew environment variables with this command in .zprofile
:
eval "$(/opt/homebrew/bin/brew shellenv)"
And was loading NVM in .zshenv
per the suggestion from React Native so that Xcode can find node:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
I resolved it by adding the unset command as the NVM output suggests:
unset PREFIX # Workaround for homebrew
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
In fact, I switched to https://github.com/lukechilds/zsh-nvm, which loads NVM as a zsh plugin (using manual installation to ~/.zsh-nvm/
), and now get autocomplete and lazy loading. 🎉 In .zhenv
:
# NVM as zsh plugin: https://github.com/lukechilds/zsh-nvm
# Upgrade NVM with `nvm upgrade`
unset PREFIX # Workaround for homebrew
export NVM_COMPLETION=true
export NVM_LAZY_LOAD=true
export NVM_LAZY_LOAD_EXTRA_COMMANDS=('yarn')
source ~/.zsh-nvm/zsh-nvm.plugin.zsh
Operating system and version:
nvm debug
output:nvm ls
output:How did you install
nvm
?install script in readme
What steps did you perform?
zsh
nvm ls
What happened?
On step 2, an error message appears:
And, on step 3, the selected node version is
system
.What did you expect to happen?
No message is shown when the sub-shell starts and the selected node version should be
v16.15.1
.Is there anything in any of your profile files that modifies the
PATH
?.zshrc
.zshenv
.cargo/env