Nvm on Windows

Hello:

I’m trying to downgrade the node environment in a windows executor. Specifically, my configuration looks like this:

version: 2.1
orbs:
  win: circleci/windows@2.2.0
jobs:
  build:
    executor:
      name: win/default
      shell: bash.exe
    steps:
      - checkout
      - run:
          name: Install NVM
          command: choco install nvm
      - run:
          name: Install Node 11.15.0
          shell: bash.exe
          command: |
              set +e
              touch $BASH_ENV
              echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
              echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
              echo 'nvm install v11.15.0' >> $BASH_ENV
              echo 'nvm use v11.15.0' >> $BASH_ENV
              echo 'node --version' >> $BASH_ENV
      #- run: npm install
      - run:
          name: Verify Node Version
          shell: bash.exe
          command: node --version
workflows:
    build:
      jobs:
        - build

When these builds are run, the job “Verify Node Version” results in:

Now using node v11.15.0 (64-bit)
/tmp/.bash_env-5e616cc5c8ed5d059c07c545-0-build: line 6: node: command not found
bash: node: command not found

Exited with code exit status 127

However, when I SSH into this machine, I can run node --version without issue, and it gives me 11.15.0. Thoughts on what I might be doing incorrectly here?

Hello

We are following up on old issues in case they can help other people.

You were very close but you did not need the echo and output to $BASH_ENV without.

Below is a revised config that will install Node 11.15.0 and set it.

version: 2.1
orbs:
  win: circleci/windows@2.2.0
jobs:
  build:
    executor:
      name: win/default
      shell: bash.exe
    steps:
      - checkout
      - run:
          name: Install NVM
          command: choco install nvm
      - run:
          name: Install Node 11.15.0
          shell: bash.exe
          command: |
              nvm list
              nvm install 11.15.0
              nvm use 11.15.0
      #- run: npm install
      - run:
          name: Verify Node Version
          shell: bash.exe
          command: node --version
workflows:
    build:
      jobs:
        - build

From the build output

#!bash.exe
node --version
v11.15.0

Kind Regards
Owen Oliver

1 Like