Circleci 2.0 installing nvm on docker executor fails

I’m trying to install nvm and set the node version based on the .nvmrc in my app

I have tried almost every potential suggestion from all other threads and it doesn’t reliably work.

I have to highlight, that on 1 app I have got it working with this solution, however, trying the same exact method on another app it fails with exit status 3.

To be clear my build process fails at the following command as shown in my full config at the bottom:

nvm install
NODE_VERSION=$(node -v)
nvm alias default ${NODE_VERSION//v}

The failure is:

Exited with code exit status 3
CircleCI received exit code 3

This comment suggests that this could occur when one would source inside the same dir as an .nvmrc file, so, I have tried to cd .. then back in to the dir to nvm install after sourcing, however I get the same result Exited with code exit status 3:

- run:
    name: Install nvm
    command: |
      cd ..
      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
      echo 'export NVM_DIR=$HOME/.nvm' >> $BASH_ENV
      echo 'source $NVM_DIR/nvm.sh' >> $BASH_ENV
- run:
    name: Set node to version required by application for future circleci steps
    command: |
      cd ~/repo
      nvm install
      NODE_VERSION=$(node -v)
      nvm alias default ${NODE_VERSION//v}

Full config without cding:

version: 2
jobs:
  node-setup:
    docker:
      - image: circleci/python:3.7
    working_directory: ~/repo
    steps:
      - checkout
      - setup_remote_docker:
          docker_layer_caching: true
      - run:
          name: Install nvm
          command: |
            curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
            echo 'export NVM_DIR=$HOME/.nvm' >> $BASH_ENV
            echo 'source $NVM_DIR/nvm.sh' >> $BASH_ENV
      - run:
          name: Set node to version required by application for future circleci steps
          command: |
            nvm install
            NODE_VERSION=$(node -v)
            nvm alias default ${NODE_VERSION//v}
      - run:
          name: node version
          command: |
            node -v

Additionally, Trying this solution results in a failure too, though I am aware this is for machine not docker:

#!/bin/bash -eo pipefail
node -v
/bin/bash: node: command not found
Exited with code exit status 127
CircleCI received exit code 127

Any help would be appreciated,
Thanks in advance,
Joe

I have figured out my issue it seems…

For some reason it works with: - image: circleci/python:3.7-node
not: - image: circleci/python:3.7,
strange, I didn’t realise you need node for the thing that installs node

Doesn’t appear to show as being a prerequisite on https://github.com/nvm-sh/nvm#system-version-of-node but whatever :woman_shrugging:

This has always worked for us…(snippets of our deploy steps)

setupNvm: &setupNvm
  name: Setup NVM
  command: |
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
    echo 'export NVM_DIR=$HOME/.nvm' >> $BASH_ENV
    echo 'source $NVM_DIR/nvm.sh' >> $BASH_ENV
setupNode: &setupNode
  name: Setup Node
  command: |
    nvm install 12.13
    nvm use node
    node -v
    npm i -g npm@6.12.0
    npm -v

Worked!

  • image: circleci/python:3.7-node

Thanks