question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SyntaxError: Unexpected token '?' on Amazon Linux 2 CodeBuild images (Node 14 required starting at 2.28.0)

See original GitHub issue

Describe the bug

Running command cdk synth with latest aws-cdk from npm produces an error.

Expected Behavior

I made no changes to source. The install step installs the most recent aws-cdk and it seems this error came with the newest version.

Current Behavior

[Container] 2022/06/14 18:50:24 Running command cdk synth
--
663 | /usr/local/lib/node_modules/aws-cdk/lib/index.js:12322
664 | return process.env.CDK_HOME ? path.resolve(process.env.CDK_HOME) : path.join((os.userInfo().homedir ?? os.homedir()).trim() \|\| "/", ".cdk");

SyntaxError: Unexpected token '?'
--
668 | at wrapSafe (internal/modules/cjs/loader.js:915:16)
669 | at Module._compile (internal/modules/cjs/loader.js:963:27)
670 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
671 | at Module.load (internal/modules/cjs/loader.js:863:32)
672 | at Function.Module._load (internal/modules/cjs/loader.js:708:14)
673 | at Module.require (internal/modules/cjs/loader.js:887:19)
674 | at require (internal/modules/cjs/helpers.js:74:18)
675 | at Object.<anonymous> (/usr/local/lib/node_modules/aws-cdk/bin/cdk.js:3:15)
676 | at Module._compile (internal/modules/cjs/loader.js:999:30)
677 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

Reproduction Steps

npm install -g aws-cdk
cdk synth

Possible Solution

No response

Additional Information/Context

I was able to explicitly install version 2.27.0 to confirm this is an issue with 2.28.0 (but I still have this problem later in the self mutate phase where I can’t control the version). This was all done on a .NET CDK app. My apologies for the lack of info I know you need more I am just trying to get some attention on this as soon as I can.

CDK CLI Version

aws-cdk@2.28.0

Framework Version

No response

Node.js Version

12.22.12

OS

Linux

Language

.NET

Language Version

No response

Other information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:13
  • Comments:46 (11 by maintainers)

github_iconTop GitHub Comments

9reactions
bentoncommented, Jun 14, 2022

I think this is because of the NodeJS version 12, as I can reproduce it with Node 12 but not with Node 16.

When using the CDK with Node 12, I get the warning:

npm WARN notsup Unsupported engine for aws-cdk@2.28.0: wanted: {"node":">= 14.15.0"} (current: {"node":"12.22.2","npm":"6.14.13"})
npm WARN notsup Not compatible with your version of node/npm: aws-cdk@2.28.0

The problem is that when deploying to production, the standard CDK Pipeline image (for ARM anyway) is outdated! The latest version of Node in the AmazonLinux2 package repo for ARM is still 12!

Plus, even if you try to pin the version of the CDK in your build, the built-in SelfMutate / UpdatePipeline step still tries to run

npm install -g aws-cdk@2

which then prints the above warning, and proceeds to fail with the error cited in the original post for this issue.

[Container] 2022/06/14 20:05:12  BUILD: 1 commands
[Container] 2022/06/14 20:05:12 Phase complete: DOWNLOAD_SOURCE State: SUCCEEDED
[Container] 2022/06/14 20:05:12 Phase context status code:  Message: 
[Container] 2022/06/14 20:05:12 Entering phase INSTALL
[Container] 2022/06/14 20:05:12 Running command npm install -g aws-cdk@2
/usr/local/bin/cdk -> /usr/local/lib/node_modules/aws-cdk/bin/cdk
npm WARN notsup Unsupported engine for aws-cdk@2.28.0: wanted: 
{
    "node": ">= 14.15.0"
}
 (current: 
{
    "node": "12.22.2",
    "npm": "6.14.13"
}
)    
npm WARN notsup Not compatible with your version of node/npm: aws-cdk@2.28.0
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/aws-cdk/node_modules    /fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted 
{
    "os": "darwin",
    "arch": "any"
}
 (current: 
{
    "os": "linux",
    "arch": "arm64"
}
)

+ aws-cdk@2.28.0
added 1 package from 1 contributor in 2.327s

[Container] 2022/06/14 20:05:22 Phase complete: INSTALL State: SUCCEEDED
[Container] 2022/06/14 20:05:22 Phase context status code:  Message: 
[Container] 2022/06/14 20:05:22 Entering phase PRE_BUILD
[Container] 2022/06/14 20:05:22 Phase complete: PRE_BUILD State: SUCCEEDED
[Container] 2022/06/14 20:05:22 Phase context status code:  Message: 
[Container] 2022/06/14 20:05:23 Entering phase BUILD
[Container] 2022/06/14 20:05:23 Running command cdk -a . deploy Pipeline --require-approval=never --verbose
/usr/local/lib/node_modules/aws-cdk/lib/index.js:12322
  return process.env.CDK_HOME ? path.resolve(process.env.CDK_HOME) : path.join((os.userInfo().homedir ??         os.homedir()).trim() || "/", ".cdk");
                                                                                                   ^

SyntaxError: Unexpected token '?'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/aws-cdk/bin/cdk.js:3:15)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

[Container] 2022/06/14 20:05:23 Command did not exit successfully cdk -a . deploy Pipeline --require-    approval=never --verbose exit status 1
[Container] 2022/06/14 20:05:23 Phase complete: BUILD State: FAILED

Please update the aws_cdk.aws_codebuild.LinuxBuildImage.AMAZON_LINUX_2_ARM_2 image ASAP! Production pipelines for ARM are broken!

5reactions
tmitchel2commented, Jun 14, 2022

Im getting this and its super annoying, it’s because the new cdk version 2.28.0 requires nodejs v14+. Unfortunately, Im using AMAZON_LINUX_2_ARM_2 and that build image doesn’t even have the option to use a more recent version.

First attempt at workaround

Im attempting to use the ‘n’ command as below: installCommands:[n 16.15.1’] However, this still only gets you up to the update-pipeline phase and that still errors out as you can’t control the node version in that phase

Second attempt at workaround

Is to pin the cdk version to the previous version rather than use ^2.0.0… Im trying that now. Nope doesn’t work as per beton’s comment

PLEASE AWS can you upgrade all your build images to support cdk, namely nodejs 14+

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS-ec2 SyntaxError: Unexpected token '.' after update node ...
I get the following error when I fire the above command. enter image description here. node version 14.15.0 . (tried in another version...
Read more >
Unexpected token '?' on Amazon Linux 2 CodeBuild images ...
SyntaxError : Unexpected token '?' on Amazon Linux 2 CodeBuild images (Node 14 required starting at 2.28.0) ... This issue has been created...
Read more >
SyntaxError: Unexpected token '?' on Amazon Linux 2 ...
SyntaxError : Unexpected token '?' on Amazon Linux 2 CodeBuild images (Node 14 required starting at 2.28.0)
Read more >
aws-sdk | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
https://raw.githubusercontent.com/jenkins-infra/je...
Plugins using this or a later version of Jenkins as baseline need to use plugin ... mainly for the benefit of Pipeline node...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found