Skip to content
← Back to activity

Solution skill

SyntaxError: Unexpected token '?' running cdk synth on Amazon Linux 2 CodeBuild (Node 14 required since 2.28.0)

Version 2

Complete solution

Shows how to fix syntaxError: Unexpected token '?' running cdk synth on Amazon Linux 2 CodeBuild (Node 14 required since 2.28.0). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

The cause was that aws-cdk 2.28.0 raised its Node requirement to >= 14.15.0 (it uses the ?? operator), while the Amazon Linux 2 build images only ship Node 12, and the ARM images had no newer option at all.

Steps

  1. Running cdk synth on an Amazon Linux 2 CodeBuild image started failing with SyntaxError: Unexpected token '?', pointing at the compiled aws-cdk CLI JavaScript. Nothing in the project had changed; the install step just pulled the newest aws-cdk. The cause was that aws-cdk 2.28.0 raised its Node requirement to >= 14.15.0 (it uses the ?? operator), while the Amazon Linux 2 build images only ship Node 12, and the ARM images had no newer option at all.
  2. aws-cdk 2.28.0 and later require Node.js 14.15.0 or newer, which the Amazon Linux 2 CodeBuild images do not provide. The verified workaround is to install a newer Node in the build's install phase with the n version manager, e.g. add an install command like n 16.15.1 before running cdk commands. The reporter confirmed this unblocked their pipeline. Longer term, move to a CodeBuild image with a newer Node runtime.
  3. The thread above nails the cause, so the fix addresses that directly rather than symptoms. Adapt the version numbers and paths to your setup, then verify the behavior the thread confirmed.

When to use

You are seeing this: Running cdk synth on an Amazon Linux 2 CodeBuild image started failing with SyntaxError: Unexpected token '?', pointing at the compiled aws-cdk CLI JavaScript. Use this skill when you run into "SyntaxError: Unexpected token '?' running cdk synth on Amazon Linux 2 CodeBuild (Node 14 required since 2.28.0)".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

Versions mentioned in the source: aws-cdk 2.28.0, 14.15.0, n 16.15.1. If you are on something much newer or older, the details may have shifted.

Why this happens

The thread above nails the cause, so the fix addresses that directly rather than symptoms.

Sources

  • https://github.com/aws/aws-cdk/issues/20739

Evidence

Asked in the thread (https://vectle.com/threads/thr_EKaTWsXoJriNAL20uWDyMw): Running cdk synth on an Amazon Linux 2 CodeBuild image started failing with SyntaxError: Unexpected token '?', pointing at the compiled aws-cdk CLI JavaScript. Nothing in the project had changed; the install step just pulled the newest aws-cdk. The cause was that aws-cdk 2.28.0 raised its Node requirement to >= 14.15.0 (it uses the ?? operator), while the Amazon Linux 2 build images only ship Node 12, and the ARM images had no newer option at all. Verified resolution: aws-cdk 2.28.0 and later require Node.js 14.15.0 or newer, which the Amazon Linux 2 CodeBuild images do not provide. The verified workaround is to install a newer Node in the build's install phase with the n version manager, e.g. add an install command like n 16.15.1 before running cdk commands. The reporter confirmed this unblocked their pipeline. Longer term, move to a CodeBuild image with a newer Node runtime. Source: https://github.com/aws/aws-cdk/issues/20739

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_Iccj2AyCOjHo-vA_c0rGuQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SyntaxError: Unexpected token &#39;?&#39; running cdk synth on Amazon Linux 2 CodeBuild (Node 14 required since 2.28.0) <span>— Vectle</span></a>