Search code examples
node.jsaws-cdk

Running aws-cdk --version and I get SyntaxError: Unexpected token?


I am trying to set up a new machine to work on some cdk code. I am working through the cdk workshop on Amazon's website. When I run aws-cdk --version I get the following:

C:\Users\u176773\AppData\Roaming\npm\node_modules\aws-cdk\lib\index.js:2

${errors.map(e=>e.stack).join("\n")}`)}}static saveManifest(manifest,filePath,schema,preprocess){let withVersion={...manifest,version:_Manifest.version()};_Manifest.validate(withVersion,schema);if(preprocess){withVersion=preprocess(withVersion)}fs.writeFileSync(filePath,JSON.stringify(withVersion,void 0,2))}static loadManifest(filePath,schema,preprocess,options){const contents=fs.readFileSync(filePath,{encoding:"utf-8"});let obj;try{obj=JSON.parse(contents)}catch(e){throw new Error(`${e.message}, while parsing ${JSON.stringify(contents)}`)}if(preprocess){obj=preprocess(obj)}_Manifest.validate(obj,schema,options);return obj}static patchStackTagsOnRead(manifest){return _Manifest.replaceStackTags(manifest,tags=>tags.map(diskTag=>({key:diskTag.Key,value:diskTag.Value})))}static patchStackTagsOnWrite(manifest){return _Manifest.replaceStackTags(manifest,tags=>tags.map(memTag=>"Key"in memTag?memTag:{Key:memTag.key,Value:memTag.value}))}static

 

SyntaxError: Unexpected token ?

at Module._compile (internal/modules/cjs/loader.js:723:23)

at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

at Module.load (internal/modules/cjs/loader.js:653:32)

at tryModuleLoad (internal/modules/cjs/loader.js:593:12)

at Function.Module._load (internal/modules/cjs/loader.js:585:3)

at Module.require (internal/modules/cjs/loader.js:692:17)

at require (internal/modules/cjs/helpers.js:25:18)

at Object.<anonymous> (C:\Users\u176773\AppData\Roaming\npm\node_modules\aws-cdk\bin\cdk.js:3:15)

at Module._compile (internal/modules/cjs/loader.js:778:30)

at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

before running this I ran this statement to install aws-cdk:

C:\Users\u176773\cdk-workshop>npm install -g aws-cdk
C:\Users\u176773\AppData\Roaming\npm\cdk -> C:\Users\u176773\AppData\Roaming\npm\node_modules\aws-cdk\bin\cdk

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\aws-cdk\node_modules\fsevents):

npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

 

+ [email protected]

updated 1 package in 1.847s

I understand the error messages are for optional dependencies.


Solution

  • Just got this exact error, right down to the line number in aws-cdk\bin\cdk.js.

    My NodeJS version needed to be updated. For cdk v2 the minimum required version is 14.5.0.