Sublime Forum

Node version is incorrect when running precommit hooks

#1

My node version is showing as 14.x even though my NVM configuration is set to default to 16.x. This is breaking my precommit hooks and making Sublime Merge unusable.

My precommit hook script runs one of the following commands:

> nyc mocha -r sucrase/register -n no-experimental-fetch './test/**/*.js'

But the no-experimental-fetch flag is not supported for Node 14 binary. So I see this error:

/Users/samholmes/.nvm/versions/node/v14.15.0/bin/node: bad option: --no-experimental-fetch

When I run node -v from my terminal I see:

❯ node -v
v16.15.1

Which is correct because NVM is set to use v16.15.1 as the default:

❯ nvm ls
       v10.23.0
       v12.19.0
       v14.15.0
       v14.17.5
->     v16.15.1
       v18.13.0
        v19.4.0
         system
default -> 16 (-> v16.15.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v19.4.0) (default)
stable -> 19.4 (-> v19.4.0) (default)
lts/* -> lts/hydrogen (-> v18.13.0)
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.21.2 (-> N/A)
lts/gallium -> v16.19.0 (-> N/A)
lts/hydrogen -> v18.13.0

Why is sublime merge not reading my ZSH configuration files properly?

Here is are ZSH files:

.zshenv

echo "loaded .zshenv"

. "$HOME/.cargo/env"

XDG_CONFIG_DIR="$HOME/.config"

export LOADED="$LOADED .zshenv"

export PATH="$HOME/.radicle/bin:$PATH"

export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"

# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

# PATH
export PATH="$HOME/bin:$PATH"
# export PATH="$PATH:$(yarn global bin)"
# export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="/usr/local/sbin:$PATH"
export PATH="/Users/samholmes/.deno/bin:$PATH"
if [[ "$(/usr/bin/arch)" = "arm64" ]]; then
  eval "$(/opt/homebrew/bin/brew shellenv)"
fi



# Android NDK env var for building Edge React GUI
#export ANDROID_NDK_HOME=/Users/samholmes/Library/Android/sdk/ndk-bundle
#export NDK_HOME=/Users/samholmes/Library/Android/sdk/ndk-bundle
#export SDK_HOME=/Users/samholmes/Library/Android/sdk
#export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
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


# export PATH="ZSHENV:$PATH"

.zshrc

echo "loaded .zshrc"

export LOADED="$LOADED .zshrc"

# Aliases
alias rc="$EDITOR $HOME/.zshrc && source $HOME/.zshrc"
alias rerc=". $HOME/.zshrc"
alias alias l="ls -al"
alias lemmeknow='afplay /System/Library/Sounds/Submarine.aiff'
alias yip="$HOME/yip"
alias yall="yarn && yarn prepare && yarn prepare.ios"
alias yuck="rm -rf node_modules ios/Pods && yarn && yarn prepare && yarn prepare.ios && lemmeknow"
alias indexbundle="(curl 'http://localhost:8101/plugin-bundle.js' || curl 'http://localhost:8081/index.bundle?platform=ios') > /tmp/index.bundle.js && $EDITOR /tmp/index.bundle.js"
alias code="code-insiders"
# alias eslintfmt="eslint --stdin --fix-dry-run --format=json | jq -r '.[0].output'"

# PATH
export PATH="$HOME/bin:$PATH"
export PATH="$PATH:$(yarn global bin)"
# export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="/usr/local/sbin:$PATH"
export PATH="/Users/samholmes/.deno/bin:$PATH"
if [[ "$(/usr/bin/arch)" = "arm64" ]]; then
  eval "$(/opt/homebrew/bin/brew shellenv)"
fi

export EDITOR=$(which hx)

# Kitty SSH Fix
[[ "$TERM" == "xterm-kitty" ]] && alias ssh="kitty +kitten ssh"

# Pure
fpath+=$HOME/.zsh/pure
autoload -U promptinit; promptinit
prompt pure
zstyle :prompt:pure:prompt:success color green

# lf command
LFX="$HOME/.config/lf/lfx.sh"
if [ -f "$LFX" ]; then
  source "$LFX"
fi
alias lf="lfx"


# Android NDK env var for building Edge React GUI
#export ANDROID_NDK_HOME=/Users/samholmes/Library/Android/sdk/ndk-bundle
#export NDK_HOME=/Users/samholmes/Library/Android/sdk/ndk-bundle
#export SDK_HOME=/Users/samholmes/Library/Android/sdk
#export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
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

# Termbin
alias tb="nc termbin.com 9999"

# NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

####################
# Custom Functions #
####################

source $HOME/.functions.sh

source /Users/samholmes/.config/broot/launcher/bash/br

function za() {
  if [[ -z $(zellij list-sessions | grep main) ]]; then
    zellij --session main
  else
    zellij attach main
  fi
  # if [[ $? == '0' ]]; then
  #   exit
  # fi
  # zellij options --simplified-ui true
}

# if [[ $TERM_APP == 'alacritty' && -z "${ZELLIJ}" ]]; then
#   zel();
# fi

export PATH="$PATH:/Users/samholmes/.foundry/bin"
export PATH=$PATH:$HOME/.maestro/bin


# export PATH="ZSHRC:$PATH"

.zprofile

#eval "$(/opt/homebrew/bin/brew shellenv)"

echo "loaded .zprofile"

export LOADED="$LOADED .zprofile"

[ -f ~/.config/LF_ICONS ] && {
  LF_ICONS="$(tr '\n' ':' <~/.config/LF_ICONS)" \
    && export LF_ICONS
}

You can probably tell I’ve added some echo statements for debugging purposes (none of which show up in the Sublime Merge output). You probably notice a bit of duplication within my files which is also from debugging this problem.

Please someone help me figure out how to make Sublime Merge work again.

0 Likes

#2

Do you see any errors in the console, something along the lines of “no output from shell” perhaps? (Tools > Show Console)

0 Likes

#3

Here is the original console output on fresh start:

startup, version: 2083 osx arm64
executable: /Applications/Sublime Merge.app/Contents/MacOS/sublime_merge
application: /Applications/Sublime Merge.app
working dir: /
packages path: /Users/samholmes/Library/Application Support/Sublime Merge/Packages
state path: /Users/samholmes/Library/Application Support/Sublime Merge/Local
zip path: /Users/samholmes/Library/Application Support/Sublime Text 3/Installed Packages
zip path: /Applications/Sublime Merge.app/Contents/MacOS/Packages
zip path: /Users/samholmes/Library/Application Support/Sublime Merge/Installed Packages
ignored_packages: ["Vintage"]
pre session restore time: 0.165632
OpenGL Context Information:
  GL API Version: 4.1 Metal - 76.3
  GLSL Version: 4.10
  Vendor: Apple
  Renderer: Apple M1 Max
loading repo /Users/samholmes/Developer/edge-react-gui/.git
loading dictionary Packages/Language - English/en_US.dic
loading repo /Users/samholmes/Developer/edge-login-ui-rn/.git
loading repo /Users/samholmes/Developer/edge-currency-monero/.git
loading repo /Users/samholmes/Developer/edge-core-js/.git
loading repo /Users/samholmes/Developer/edge-currency-plugins/.git
loading repo /Users/samholmes/Developer/nopacity/monopacity/.git
loading repo /Users/samholmes/Developer/nopacity/nopacity/.git
first paint time: 0.250868
head changed to a236aff240181b5ea5571ce2acb15ff16af18d91
head changed to 869691678bf8ae4fe0b342afbe3b9081e1a8635d
head changed to c20e625c9ac11b5283b4a1d5d6f874fa46dd964b
head changed to b3690efdf4e0de0c01a6130bd627170928a88745
head changed to 17917aa531963be2bae757da67db0c42f51cdabb
head changed to 06a23ba8a4c14763c044bea1a90f510779685a69
head changed to 1c0615d01d03a8a5a21e106e6b8e68c08735a072

Here’s the console output after staging a file and trying to commit:

startup, version: 2083 osx arm64
executable: /Applications/Sublime Merge.app/Contents/MacOS/sublime_merge
application: /Applications/Sublime Merge.app
working dir: /
packages path: /Users/samholmes/Library/Application Support/Sublime Merge/Packages
state path: /Users/samholmes/Library/Application Support/Sublime Merge/Local
zip path: /Users/samholmes/Library/Application Support/Sublime Text 3/Installed Packages
zip path: /Applications/Sublime Merge.app/Contents/MacOS/Packages
zip path: /Users/samholmes/Library/Application Support/Sublime Merge/Installed Packages
ignored_packages: ["Vintage"]
pre session restore time: 0.165632
OpenGL Context Information:
  GL API Version: 4.1 Metal - 76.3
  GLSL Version: 4.10
  Vendor: Apple
  Renderer: Apple M1 Max
loading repo /Users/samholmes/Developer/edge-react-gui/.git
loading dictionary Packages/Language - English/en_US.dic
loading repo /Users/samholmes/Developer/edge-login-ui-rn/.git
loading repo /Users/samholmes/Developer/edge-currency-monero/.git
loading repo /Users/samholmes/Developer/edge-core-js/.git
loading repo /Users/samholmes/Developer/edge-currency-plugins/.git
loading repo /Users/samholmes/Developer/nopacity/monopacity/.git
loading repo /Users/samholmes/Developer/nopacity/nopacity/.git
first paint time: 0.250868
head changed to a236aff240181b5ea5571ce2acb15ff16af18d91
head changed to 869691678bf8ae4fe0b342afbe3b9081e1a8635d
head changed to c20e625c9ac11b5283b4a1d5d6f874fa46dd964b
head changed to b3690efdf4e0de0c01a6130bd627170928a88745
head changed to 17917aa531963be2bae757da67db0c42f51cdabb
head changed to 06a23ba8a4c14763c044bea1a90f510779685a69
head changed to 1c0615d01d03a8a5a21e106e6b8e68c08735a072
Executing: git add -- src/xmrEngine.js
Working dir: /Users/samholmes/Developer/edge-currency-monero
  Env vars: USER=samholmes __CFBundleIdentifier=com.sublimemerge COMMAND_MODE=unix2003 LOGNAME=samholmes SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.xwGejLrmjq/Listeners SHELL=/bin/zsh HOME=/Users/samholmes __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0 TMPDIR=/var/folders/zc/5y7_0xj96sq01_56d8h8mb940000gn/T/ XPC_SERVICE_NAME=0 XPC_FLAGS=0x0 OLDPWD=/ LOADED= .zshenv .zprofile NVM_DIR=/Users/samholmes/.nvm NVM_CD_FLAGS=-q NVM_BIN=/Users/samholmes/.nvm/versions/node/v16.15.1/bin NVM_INC=/Users/samholmes/.nvm/versions/node/v16.15.1/include/node HOMEBREW_PREFIX=/opt/homebrew HOMEBREW_CELLAR=/opt/homebrew/Cellar HOMEBREW_REPOSITORY=/opt/homebrew MANPATH=/usr/share/man:/usr/local/share/man:/opt/homebrew/share/man INFOPATH=/opt/homebrew/share/info: ANDROID_HOME=/Users/samholmes/Library/Android/sdk PATH=/Users/samholmes/.nvm/versions/node/v14.15.0/bin:/Users/samholmes/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin GIT_EDITOR=/usr/bin/true GIT_PAGER=cat
Result: success
Error loading Packages/Diff/Diff.sublime-syntax: Unable to read Packages/Diff/Diff.sublime-syntax in Packages/Default/Commit Message.sublime-syntax
Executing: git commit -q -m Test
Working dir: /Users/samholmes/Developer/edge-currency-monero
  Env vars: USER=samholmes __CFBundleIdentifier=com.sublimemerge COMMAND_MODE=unix2003 LOGNAME=samholmes SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.xwGejLrmjq/Listeners SHELL=/bin/zsh HOME=/Users/samholmes __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0 TMPDIR=/var/folders/zc/5y7_0xj96sq01_56d8h8mb940000gn/T/ XPC_SERVICE_NAME=0 XPC_FLAGS=0x0 OLDPWD=/ LOADED= .zshenv .zprofile NVM_DIR=/Users/samholmes/.nvm NVM_CD_FLAGS=-q NVM_BIN=/Users/samholmes/.nvm/versions/node/v16.15.1/bin NVM_INC=/Users/samholmes/.nvm/versions/node/v16.15.1/include/node HOMEBREW_PREFIX=/opt/homebrew HOMEBREW_CELLAR=/opt/homebrew/Cellar HOMEBREW_REPOSITORY=/opt/homebrew MANPATH=/usr/share/man:/usr/local/share/man:/opt/homebrew/share/man INFOPATH=/opt/homebrew/share/info: ANDROID_HOME=/Users/samholmes/Library/Android/sdk PATH=/Users/samholmes/.nvm/versions/node/v14.15.0/bin:/Users/samholmes/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin GIT_EDITOR=/usr/bin/true GIT_PAGER=cat
Result: failed with exit code 1

You can see how the Env vars are all messed up. It looks nothing like the env vars that I have in my terminal applications (Alacritty, VSCode integrated terminal, etc).

0 Likes

#4

You can see how the Env vars are all messed up. It looks nothing like the env vars that I have in my terminal applications (Alacritty, VSCode integrated terminal, etc).

Note Sublime Merge will not load environment variables from your .zshrc as it uses a login shell. From the output LOADED= .zshenv .zprofile it looks like those were loaded correctly?

1 Like

#5

It does indeed look like .zshenv and .zprofile are loaded, but I don’t know about “correctly”. Looking at .zshenv, it looks like NVM is being setup in that file. Why then, is the node version incorrect?

0 Likes

#6

Circling back around to this issue.

The two startup files (.zshenv and .zprofile) are loading correctly. You can tell that some env contains the right version (v16.15.1), but if you look closely at the PATH env, you’ll see a path to /Users/samholmes/.nvm/versions/node/v14.15.0/bin is present. This leads me to believe that somewhere the incorrect version is being injected into this PATH env, but I’m unsure if it’s from Sublime Merge, or the login shell when only loading the two startup files.

What I did is add export LOADED="$LOADED $PATH" to .zprofile file in order to see what PATH is while the startup files are running. The result is a different PATH then what I’m seeing Sublime Merge include in the command execution:

Executing: git commit -q -m Test
Working dir: /Users/samholmes/Developer/edge-currency-accountbased
  Env vars: USER=samholmes COMMAND_MODE=unix2003 __CFBundleIdentifier=com.sublimemerge LOGNAME=samholmes SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.Vs4brj4VUZ/Listeners HOME=/Users/samholmes SHELL=/bin/zsh TMPDIR=/var/folders/zc/5y7_0xj96sq01_56d8h8mb940000gn/T/ __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0 XPC_SERVICE_NAME=0 XPC_FLAGS=0x0 OLDPWD=/ LOADED= .zshenv .zprofile /usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/samholmes/.nvm/versions/node/v16.15.1/bin:/Users/samholmes/.cargo/bin NVM_DIR=/Users/samholmes/.nvm NVM_CD_FLAGS=-q NVM_BIN=/Users/samholmes/.nvm/versions/node/v16.15.1/bin NVM_INC=/Users/samholmes/.nvm/versions/node/v16.15.1/include/node PATH=/Users/samholmes/.nvm/versions/node/v14.15.0/bin:/Users/samholmes/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin GIT_EDITOR=/usr/bin/true GIT_PAGER=cat

Notice the LOADED env is:

LOADED= .zshenv .zprofile /usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/samholmes/.nvm/versions/node/v16.15.1/bin:/Users/samholmes/.cargo/bin

Which is correct and the expected PATH after loading my startup files; notice the v16.15.1 node version in the PATH.

Compare this to the PATH env being sent:

PATH=/Users/samholmes/.nvm/versions/node/v14.15.0/bin:/Users/samholmes/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

Perhaps Sublime Merge is injecting a PATH that isn’t built by the startup files? It’s clear that the PATH is unaffected by my startup files and this my be a bug in Sublime Merge rather than my ZSH setup.

0 Likes

#7

Problem solved!

The issue was that I had this in my Preferences.sublime-settings:

	"git_env": {
		"PATH": "/Users/samholmes/.nvm/versions/node/v14.15.0/bin:/Users/samholmes/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin",
	},

This was overriding the PATH from my startup scripts. Sheesh. I removed it and it now works perfectly.

2 Likes