22

I have a confusing issue with AWS CodeBuild. I am getting the following error:

Major version of alias '14.x' is not supported in runtime 'nodejs'

When I update the buildspec to simply be "14" I get slightly more information on the error:

Message: Unknown runtime version named '14' of nodejs. This build image has the following versions: 10, 12

We have been using this CodeBuild project for a long time using 12.x and now require to update to 14.x. We have updated the buildspec as follows:

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 14.x

  build:
    commands:
      - "npm i"
      - "npm run build"
      - "npm run db:migrate"

artifacts:
  files:
    - "all"
    - "of"
    - "our"
    - "files"

Additionally, our CodeBuild is already on the latest version of the CodeBuild image. I have even re-built the CodeBuild project to make sure it is the latest and still the same issue:

aws/codebuild/amazonlinux2-x86_64-standard:3.0

Thank you in advance for any advice.

Ollie
  • 1,355
  • 1
  • 10
  • 22

3 Answers3

37

Thankfully we have solved this now!

The issue was with the CodeBuild image:

aws/codebuild/amazonlinux2-x86_64-standard:3.0

As per the available runtimes documentation it turns out we cannot use Amazon Linux 2 at all, we had to change to "Ubuntu Standard 5".

I hope this helps someone in the future.

Ollie
  • 1,355
  • 1
  • 10
  • 22
  • 2
    6 months later and still the latest version of node on amazon linux codebuild images is 12 - a version that is now totally out of support – Andy Jun 23 '22 at 09:13
  • @Andy Are you able to run the codebuild on "Ubuntu Standard 6" now? I still seem to get the same error even after AWS saying it supports nodejs 16 in codebuild now – Nandita Sharma Sep 01 '22 at 07:55
  • This answer would be much more helpful if you provided the actual image source you replaced it with (aws/codebuild/standard:5.0). Found here: https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html – cantuket Jan 11 '23 at 20:45
18

If you absolutely need to use Amazon Linux 2 instead of Ubuntu, you can install Node 14 using the pre-installed n package in CodeBuild:

version: 0.2

phases:
  install:
    commands:
      - n 14.18.3

  build:
    commands:
      - npm i #etc

In our case we needed to build dependencies to run in Lambda. Since Lambda runs a version of Amazon Linux 2, building these dependencies in Ubuntu didn't work (for complicated sub-dependency reasons).

Tried and didn't work:

Then we realized that n was already pre-installed in CodeBuild and managing the node version.

In the end, no complicated commands needed.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Bofei Cao
  • 221
  • 1
  • 5
3

select the build image that supports your runtime from here https://docs.aws.amazon.com/codebuild/latest/userguide/available-runtimes.html

A Garhy
  • 423
  • 4
  • 8