8

When I upgraded from 1.33.0 -> 1.37.0, I started getting the error below. I reverted back to the old CDK version, and the command works again.

CDK version

$ cdk --version
1.37.0 (build e4709de)

Error:

$ cdk synth
Unexpected token '?'
Subprocess exited with error 1

Any insight as to what this error message could mean?

Leon Hsu
  • 121
  • 1
  • 4
  • It's impossible to tell from information you provided. There should be a stack trace to the point of failure, I recommend to investigate it and provide more detailed data from the area of failure. – Milan Gatyás May 06 '20 at 08:10
  • Please provide more information – Amit Baranes May 06 '20 at 09:06
  • That's literally the stack trace error that I get back. I can provide the package.json if needed. – Leon Hsu May 08 '20 at 08:01
  • If you are using Typescript, it is possible that you reverted to an old version of Typescript where the optional chain operators don't exist. – Dennis May 09 '20 at 23:58
  • Try to perform a manual typescript compilation by running 'npx tsc' (if installed locally, which you should). That should give you more insights and if you have the same issue now you know that the problem is in your ts version/config – Luca T May 11 '20 at 10:02
  • Thanks Luca & Dennis. That was the issue for me, posted an answer to the question. – Leon Hsu May 22 '20 at 20:47

3 Answers3

14

Another cause for this issue could be an outdated node version, CDK support for node 12 has been dropped in this release.

Upgrading to a supported node version resolves the issue.

Oliver
  • 8,794
  • 2
  • 40
  • 60
3

The issue was in the typescript compiler. I had the target set to ES2020 when it should've been ES2018.

Changing to the correct version fixed the issue for me.

tsconfig.json

{
  "compilerOptions": {
    "target":"ES2018",
    "module": "commonjs",
    "lib": ["es2018"],
    "declaration": true,
    "strict": true,
    ...
  }
}
Leon Hsu
  • 121
  • 1
  • 4
2

On my side, the problem had been solved by adding the following command alias to ensure to run my locally installed AWS CDK Toolkit:

alias cdk="npx aws-cdk"

More info here: https://docs.aws.amazon.com/cdk/v2/guide/troubleshooting.html