56

I'm facing the problem that I cant build my Angular app through the AWS Amplify Console: "You are running version v8.12.0 of Node.js, which is not supported by Angular CLI 8.0+. The official Node.js version that is supported is 10.9 or greater. Please visit https://nodejs.org/en/ to find instructions on how to update Node.js."

Now I want to set the default node version of the docker container in the provision step to VERSION_NODE_10 which is already defined in the container.

# Framework Versions
ENV VERSION_NODE_8=8.12.0
ENV VERSION_NODE_6=6
ENV VERSION_NODE_10=10
ENV VERSION_NODE_DEFAULT=$VERSION_NODE_8 <-- Change this to $VERSION_NODE_10
ENV VERSION_RUBY_2_3=2.3.6
ENV VERSION_RUBY_2_4=2.4.3
ENV VERSION_RUBY_DEFAULT=$VERSION_RUBY_2_3
ENV VERSION_HUGO=0.51
ENV VERSION_YARN=1.13.0

amplify.yml:

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

Does anyone know how to change the default?

2

10 Answers 10

59

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.
3
  • 2
    Here is the github thread that has this solution described in more detail with additional pictures of the Amplify console setup github.com/aws-amplify/amplify-cli/issues/3187 Commented Nov 6, 2020 at 10:32
  • 7
    Because of rate limiting from docker hub, this now fails intermittently as the amplify ip is rate limited! So I had to rollback to the nvm solution instead.
    – Kzqai
    Commented Nov 19, 2020 at 13:43
  • I found this post just now, and can confirm these steps helped me solve a similar problem to the original post. Commented Jan 7, 2024 at 19:58
47

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/**/*
8
  • Thanks! Any idea how to tell the Amplify console to install & use the node version defined in the packages.json?
    – morgler
    Commented Jan 20, 2020 at 20:13
  • Thank you for this. I am also looking to update yarn and the "Live package updates" settings in teh console don't seem to be picked up. I also tried yvm in a similar manner as nvm in this answer, but yvm is not available. Any chance you also know how to specify the version of yarn used?
    – Shawn
    Commented Apr 14, 2020 at 18:21
  • Maybe you can add in the build commands ‘- curl -o- -L yarnpkg.com/install.sh | bash‘ or ‘- npm install --global yarn‘
    – richard
    Commented Apr 16, 2020 at 12:47
  • 4
    If you keep an .nvmrc file in your repo root, it's easy to install and use any node version you want. Use preBuild commands nvm install and nvm use, without naming a specific version. (Sadly, Amplify's nvm doesn't seem to support the --no-progress option nvm added in 2018.)
    – medmunds
    Commented May 31, 2020 at 23:35
  • 1
    Why did you duplicate npm use?
    – adi518
    Commented Jul 20, 2021 at 8:50
32

Custom build image of NodeJS is a lot of pain.

I usually do this: App settings > Build Settings > Build Image Settings click Edit. Live package updates : Node.js version > version.

enter image description here

0
14

Update as of 25th Jan 2024:

It still works...

Update as of 13th Nov 2023:

It still works.

Update as of 4th Dec 2022:

What worked out for me was to use a custom build of the NodeJS Docker image on Docker Hub.

Here's what you would need to do:

  • Go to AWS Amplify
  • Go to "Build settings"
  • Scroll down to "Build image settings"
  • Click on "Edit" button
  • Under "Build image" click on the dropdown button
  • Select "Build Image" (by default Linux:2 is selected, at least for me)
  • In the text field type, for example, "node:18.12.1"
  • Go back to the latest deploy and click on the "Redeploy this version" app
  • Roll a J and smoke it, everything should be green now

In that way, you may use whatever build of NodeJS you would need. At least, NodeJS 18 worked for me, I didn't need another.

During build time you can see in the Provision tab they actually use the custom build from Docker Hub:

enter image description here


I tried two of the answers above and they did not work for me.


I didn't think of that. That approach was shared by "dncrews" user on Github. Check this out.

3
  • 2
    Works in 2024. I used node:20.9.0.
    – Karol
    Commented Jan 25, 2024 at 18:58
  • 1
    I am just starting out in amplify, trying to create a next.js app by following the tutorial. It failed in the build and was trying to use node 16.9 instead of the latest. By changing the build image to Amazon Linux:2023 instead of the Amazon Linux 2, I was able to get it to use the correct node and next versions.
    – Graeme
    Commented Feb 1, 2024 at 1:22
  • 1
    This is the correct approach Commented Oct 23, 2024 at 19:39
5

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)
3

Following on @richard's solution, you can put a .nvmrc ($ node --version > .nvmrc) file in the root of your repo with the specific Node version you used to build your project, and use nvm install instead of nvm use $VERSION_NODE_10

3

Yes, this is annoying it does not work out of the box yet (Come on AWS!) but in this issue post: https://github.com/orgs/community/discussions/72835

It states you can just add nvm use 18 to your build settings in amplify.yml and it will work.

The issue is that nextjs dropped the support of node v16 in v14 of nextjs

Here is a default yml

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - nvm use 18
        - npm ci
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Thought I would add this answer with a default yml for those who could not be bothered reading :)

1
  • this is the correct answer for Gen2 onwards
    – dota2pro
    Commented Oct 6, 2024 at 0:32
2

Currently if you choose the newer Amazon default image Amazon Linux:2023 it supports newer Node versions (18.x, 20.x) out of the box.

This should be also the default for the new projects.

enter image description here

No changes in files needed, just est a new Node.js version override from the dropdown (Live package updates).

enter image description here

1

February 2023

To do so, open amplify/backend/function/function-name/function-name-cloudformation-template.json and set the Runtime property in the LambdaFunction resource to nodejs18.x

https://docs.amplify.aws/cli/function/configure-options/#updating-the-runtime

0

I needed to bump to Node 18. The steps to follow as of today are:

  • Go to AWS Amplify
  • Go to "Build settings"
  • Scroll down to "Build image settings"
  • Click on "Edit" button Under "Build image"
  • click on Select "Build Image"
  • In the text field type, for example, "public.ecr.aws/docker/library/node:18.13.0"
  • Go back to the latest deploy and click on the "Redeploy this version" app

Hopefully it works for someone else as well. For reference you can have a look at this github issue: https://github.com/aws-amplify/amplify-hosting/issues/3109#issuecomment-1454068950

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.