Skip to content

Proposal: Update default tsconfig.json for cdk init --language=typescript to align with modern module resolution #427

@garysassano

Description

@garysassano

Describe the feature

Currently, the default tsconfig.json generated by cdk init --language=typescript uses older TypeScript settings, particularly for module and moduleResolution.

While this works for many scenarios, it can cause compatibility issues with newer versions of popular libraries within the AWS ecosystem, such as Powertools for AWS Lambda (TypeScript). These libraries are increasingly relying on the exports map in package.json for defining entry points, which requires modern moduleResolution strategies like node16, nodenext, or bundler to be correctly interpreted by TypeScript.

A recent issue (aws-powertools/powertools-lambda-typescript#3865) highlighted this problem. While Powertools temporarily restored typeVersions for backward compatibility in a minor release, they intend to rely solely on the exports map in their next major version (v3). This means CDK users who haven't updated their tsconfig.json manually will likely encounter TS2307 import errors when upgrading Powertools or other similar libraries in the future.

Describe the solution you'd like

Update the default tsconfig.json generated by cdk init --language=typescript to use more modern and forward-compatible settings. Specifically, consider aligning with the recommended settings for projects using modern Node.js features and libraries like Powertools:

Reference: Powertools for AWS Lambda (TypeScript) - Recommended Settings

Key recommended changes often include:

  • "module": "Node16" or "module": "NodeNext"
  • "moduleResolution": "Node16" or "moduleResolution": "NodeNext" (or "Bundler" depending on the target environment and bundler usage)
  • "target": "ES2022" (or a similarly modern target)

Using settings like Node16 or NodeNext for module and moduleResolution ensures that TypeScript correctly interprets the exports map in dependencies.

Use Case

See above.

Proposed Solution

See above.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.192.0

Environment details (OS name and version, etc.)

24.04

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions