SyntaxError: Unexpected token '?' on Amazon Linux 2 CodeBuild images (Node 14 required starting at 2.28.0)
See original GitHub issueDescribe 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:
- Created a year ago
- Reactions:13
- Comments:46 (11 by maintainers)
Top 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 >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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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:
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 runwhich then prints the above warning, and proceeds to fail with the error cited in the original post for this issue.
Please update the
aws_cdk.aws_codebuild.LinuxBuildImage.AMAZON_LINUX_2_ARM_2
image ASAP! Production pipelines for ARM are broken!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+