DEV Community

Cover image for Auto-loading .nvmrc in JetBrains Junie terminal
David Haley
David Haley

Posted on

Auto-loading .nvmrc in JetBrains Junie terminal

I've been using JetBrains's Junie product for agentic AI coding since it went public in April 2025. It's been an overall great experience.

I noted it was struggling with a React/TypeScript project. When running yarn commands it wasn't honoring the .nvmrc file, so it didn't load the correct node version. This caused issues for files generated/built against different NodeJS versions.

My setup is slightly strange: because NVM takes a while to load, and I'm impatient, I don't load it automatically in my shell. Whereas the usual setup would be,

[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"
Enter fullscreen mode Exit fullscreen mode

my .zsh-local-mac (included from .zshrc) sets up an alias:

alias load-nvm='[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"'
Enter fullscreen mode Exit fullscreen mode

Without that line, Junie doesn't have NVM enabled in its terminal. But just loading NVM isn't enough, we need to also load the .nvmrc file.

Junie helpfully sets the $TERMINAL_EMULATOR to JetBrains-JediTerm. So I added this to my shell config:

if [[ "$TERMINAL_EMULATOR" == "JetBrains-JediTerm" ]]; then
  load-nvm

  autoload -U add-zsh-hook
  load-nvmrc() {
    local node_version="$(nvm version)"
    local nvmrc_path="$(nvm_find_nvmrc)"

    if [ -n "$nvmrc_path" ]; then
      local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")

      if [ "$nvmrc_node_version" = "N/A" ]; then
        nvm install
      elif [ "$nvmrc_node_version" != "$node_version" ]; then
        nvm use
      fi
    elif [ "$node_version" != "$(nvm version default)" ]; then
      echo "Reverting to nvm default version"
      nvm use default
    fi
  }
  add-zsh-hook chpwd load-nvmrc
  load-nvmrc
fi
Enter fullscreen mode Exit fullscreen mode

After making this change, Junie terminals honor .nvmrc files. This is vital to run tests, e.g., yarn jest src/file.test.tsx, allowing the agent to iterate more intelligently on its progress.

Top comments (0)