awsdocs / aws-cdk-guide

User guide for the AWS Cloud Development Kit (CDK).
Other
335 stars 222 forks source link

Typescript example requires undocumented npm run build before cdk synth #284

Closed tkgregory closed 4 years ago

tkgregory commented 4 years ago

I'm following the Typescript Your first AWS CDK app example. Half way down it says:

Normally, after making any changes to your code, you'd build (compile) it. This isn't strictly necessary with the AWS CDK—the Toolkit does it for you so you can't forget.

Having made changes to hello-cdk-stack.ts to include the S3 bucket definition, the example says to run cdk synth to see the S3 bucket resource definition output in CloudFormation. This only works if I run npm run build first, which contradicts the quote above.

Please let me know if I'm doing something wrong, or amend the instructions accordingly to say that npm run build is required before cdk synth.

I'm using CDK version 1.73.0 (build eb6f3a9)

ghost commented 4 years ago

@tkgregory You're not supposed to have to rebuild, but it turns out, sometimes you do (at least if you're using TypeScript). I've narrowed this down and found a fix. If you have a moment and would like to help confirm the fix, edit your Hello CDK app's cdk.json file so the app line looks like this:

  "app": "npx ts-node --prefer-ts-exts bin/hello-cdk.ts"

The --prefer-ts-exts is the new bit there.

After making that change to cdk.json, changes to the CDK app code should be reflected on the next synth, without needing to explicitly npm run build.

I created a PR for this over on the CDK repo to add this to the TypeScript init template: https://github.com/aws/aws-cdk/pull/11470

tkgregory commented 4 years ago

@Jerry-AWS that's fixed the problem for me. Thanks for the quick response. 👍

I also spotted https://github.com/aws/aws-cdk/issues/7475 which maybe a duplicate?

ghost commented 4 years ago

@tkgregory Excellent catch on that duplicate!

ghost commented 4 years ago

The PR with the fix for this has been merged and will appear in the next release of the CDK. @tkgregory Thanks for raising this issue!

ghost commented 4 years ago

Looks like this missed the release of 1.74 by a couple hours; it will be in 1.75