aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.36k stars 3.77k forks source link

cdk-lib: Typescript template uses obsolete 'source-map-support/register' #30231

Open samloibl opened 1 month ago

samloibl commented 1 month ago

Describe the bug

When creating a Typescript project via cdk init app --language typescript, the generated code importssource-map-support/register. This library is obsolete, and is not required for node versions 12.12.0 or higher (see docs).

The library interferes with tsx, and results in invalid stack traces (see this bug report). ts-node does not appear to be affected, but stack traces equally work without the library.

Expected Behavior

source-map-support should not be included in package.json, and not be imported in the .ts file in /bin.

When running the synth using tsx instead of ts-node, stack traces for uncaught errors should be correct.

Current Behavior

The generated package.json file includes source-map-support as a dependency, and the generated .ts file in /bin includes import 'source-map-support/register';

When running the synth using tsx via npx tsx bin/<project>.ts, the stack trace will be incorrect, and point to an incorrect line number:

Error: Duh!
    at new TsxIssue447Stack (/Users/me/tsx-issue447/lib/tsx-issue447-stack.ts:2:1366)
    at /Users/me/tsx-issue447/bin/tsx-issue447.ts:3:950
    at Object.<anonymous> (/Users/me/tsx-issue447/bin/tsx-issue447.ts:4:3)

Reproduction Steps

nvm use 20
mkdir tsx-issue447 && cd tsx-issue447
npx cdk init app --language typescript
sed -i.bak 's/\/\/ The code.*$/throw new Error("Duh!");/' lib/tsx-issue447-stack.ts
npx tsx bin/tsx-issue447.ts

Possible Solution

Remove the library from dependencies, and remove the import

Changes required:

Additional Information/Context

No response

CDK CLI Version

2.141.0 (build 3d1c06e)

Framework Version

No response

Node.js Version

v20.11.1, v18.17.0, v16.20.2

OS

OSX

Language

TypeScript

Language Version

5.4.5

Other information

No response

pahud commented 1 month ago

Thank you for bringing this to our attention. We'll discuss this with the team.