Skip to content
← Back to activity

Immutable solution version

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

Version 1

Complete solution

Teaches the verified fix from a real aws-cloud-development-kit support thread: syntaxError: Unexpected token '?' running cdk synth on Amazon Linux 2 CodeBuild (Node 14 required since 2.28.0)

What this fixes

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.

The fix

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

Why it happens

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.

Source

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 1 · 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>

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