-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Describe the feature
The TypeScript template generated by cdk init app --language typescript includes a bin field in package.json:
{
"name": "my-app",
"bin": {
"my-app": "bin/my-app.js"
}
}This field should be removed from the template as it does not seem to serves any purpose for CDK apps and can cause issues.
Use Case
The bin field declares a CLI command for npm packages intended to be installed globally or via npx. A CDK app is neither. It is invoked by the CDK CLI through the app field in cdk.json (e.g. npx ts-node bin/my-app.ts).
The bin field also references bin/my-app.js, which does not exist at init time. Modern templates use ts-node/tsx to run .ts directly, so compiling to .js is not part of the expected workflow.
When the project directory is named cdk, the template generates "bin": { "cdk": "bin/cdk.js" }. If the user then runs tsc (e.g. for type-checking in CI), bin/cdk.js is emitted. At that point, npx cdk synth can resolve to this project's bin/cdk.js instead of the AWS CDK CLI via the npx cache. The CDK app is executed directly as if it were the CLI — it is not a CLI, so the behavior is completely broken.
We hit this issue in practice: aws-samples/remote-swe-agents#377
Proposed Solution
Remove the bin field from the generated package.json in the TypeScript init template. It has no effect on CDK app functionality.
Other Information
The root cause chain when the directory is named cdk:
cdk initgenerates"bin": { "cdk": "bin/cdk.js" }from the directory nametscemitsbin/cdk.js(nooutDirornoEmitin the default tsconfig)npx cdk synthresolves to this project'sbin/cdk.jsvia the npx cache instead ofaws-cdkCLI- The CDK app is executed directly as a CLI command — this is completely wrong and results in arbitrary errors
Workarounds:
- Add
"noEmit": truetotsconfig.json - Rename the
binkey to something other thancdk - Delete the
binfield frompackage.jsonafter cdk init
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
AWS CDK Library version (aws-cdk-lib)
2.187.0
AWS CDK CLI version
2.1030.0
Environment details (OS name and version, etc.)
Linux (Ubuntu 24.04 on WSL2), Node.js v24.13.1, npm 11.8.0