38

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?

Mayank Patel
  • 8,088
  • 5
  • 55
  • 75
Slohrsh
  • 595
  • 1
  • 5
  • 9

7 Answers7

42

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.
Jan Cássio
  • 2,076
  • 29
  • 41
  • 2
    Here is the github thread that has this solution described in more detail with additional pictures of the Amplify console setup https://github.com/aws-amplify/amplify-cli/issues/3187 – Erkka Mutanen Nov 06 '20 at 10:32
  • 6
    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 Nov 19 '20 at 13:43
40

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/**/*
richard
  • 597
  • 5
  • 6
  • Thanks! Any idea how to tell the Amplify console to install & use the node version defined in the packages.json? – morgler Jan 20 '20 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 Apr 14 '20 at 18:21
  • Maybe you can add in the build commands ‘- curl -o- -L https://yarnpkg.com/install.sh | bash‘ or ‘- npm install --global yarn‘ – richard Apr 16 '20 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](https://github.com/nvm-sh/nvm/pull/1422) in 2018.) – medmunds May 31 '20 at 23:35
  • 1
    Why did you duplicate `npm use`? – adi518 Jul 20 '21 at 08:50
  • how do I install node 14+? – Diego Ponciano Nov 28 '21 at 19:02
  • what if I am specifically looking to use node 16.14 ? – Fed Jun 10 '22 at 17:17
  • @FedericoCapaldo create a `.nvmrc` file at the root of project and make the contents `16.14.0` – mlg87 Jul 29 '22 at 04:38
19

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

Jim Tebstone
  • 552
  • 6
  • 13
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)
Mayank Patel
  • 8,088
  • 5
  • 55
  • 75
3

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.

tonkatata
  • 369
  • 5
  • 21
2

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

Christophe
  • 31
  • 1
  • 6
0

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

webjay
  • 5,358
  • 9
  • 45
  • 62