aws / aws/aws-cdk

lambda-nodejs: Use OutputFormat.ESM by default for .mjs and .ts files

Open
#28,840 0 comments 4 reactions 0 assignees View on GitHub
@aws-cdk/aws-lambda-nodejs effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

When my entrypoints are either .mjs and .ts files, I would like the ESM output format to be used by esbuild.

### Use Case

Both .mjs and .ts files are written with ES modules in mind. They usually use the `export const handler` syntax instead of `exports.handler`. When bundled to CJS, we get a bit of boilerplate in the output which can be prevented by automatically detecting that and using ESM output format.

### Proposed Solution

_No response_

### Other Information

_No response_

### Acknowledgements

- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.122.0

### Environment details (OS name and version, etc.)

Mac Sonoma

Contributor guide

Open the contributing guide

Research direction

Search the lambda-nodejs construct for where entrypoint extensions are handled and where esbuild OutputFormat is selected. Inspect nearby bundling tests if present, then verify that .mjs and .ts entrypoints use ESM while other entrypoints retain their existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, typescript
Domain
backend, cloud
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.