How to change Node Version in Provision Step in Amplify Console

The correct answer actually isn't the right one.

You should use a custom build image of NodeJS to run your application properly without changing the node version by nvm.

To do that:

  1. Open the "Amplify Console"
  2. Open "All Apps"
  3. Choose the app you're going to change the NodeJS version
  4. Open "Build Settings"
  5. Scroll down to "Build image settings" box and hit "edit" button
  6. At "Build Image" dropdown, choose the option "Build image"
  7. A new input field will appear just below this dropdown, now write the Docker Image Name (same used in Dockefile) you are looking for. For example node:12.16.1
  8. Save
  9. Redeploy any build.

The accepted answer did not work for me.

The only way to change the node version in the provision step is to have your own build setting.

However, there is an easier way to accomplish this.

In my case, I wanted the latest node 10 version. And adding nvm install in the prebuild step worked.

frontend:
  phases:
    preBuild:
      commands:
        - nvm install 10

You can install and use any node version in the amplify by installing it in prebuild steps. Use nvm to switch the node version.

preBuild:
  commands:
    - nvm install <node version>

Amplify Console output:

# Executing command: nvm install 10

2020-09-09T13:36:19.465Z [INFO]: Downloading and installing node v10.22.0...
2020-09-09T13:36:19.544Z [WARNING]: Downloading https://nodejs.org/dist/v10.22.0/node-v10.22.0-linux-x64.tar.gz...
2020-09-09T13:36:19.664Z [WARNING]: ########
2020-09-09T13:36:19.665Z [WARNING]: 11.9%
2020-09-09T13:36:19.765Z [WARNING]: #######
2020-09-09T13:36:19.765Z [WARNING]: ########################                                           43.5%
2020-09-09T13:36:19.832Z [WARNING]: ################################
2020-09-09T13:36:19.832Z [WARNING]: ######################################## 100.0%
2020-09-09T13:36:19.844Z [WARNING]: Computing checksum with sha256sum
2020-09-09T13:36:19.934Z [WARNING]: Checksums matched!

2020-09-09T13:36:20.842Z [INFO]: Now using node v10.22.0 (npm v6.14.6)

AWS Amplify use nvm to handle node version. Try this:

version: 0.1
backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - nvm use $VERSION_NODE_10
        - npm ci
    build:
      commands:
        - nvm use $VERSION_NODE_10
        - node -v
        - npm run-script build
  artifacts:
    baseDirectory: dist/cr-client
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*