Skip to content

Add dual CJS/ESM build#326

Open
tomassabol wants to merge 1 commit into
jeremydaly:mainfrom
tomassabol:feat/esm-dual-package
Open

Add dual CJS/ESM build#326
tomassabol wants to merge 1 commit into
jeremydaly:mainfrom
tomassabol:feat/esm-dual-package

Conversation

@tomassabol

Copy link
Copy Markdown

Summary

This PR adds dual CommonJS and ESM support.

Until now, the package has only shipped as CommonJS, which can make modern ESM bundling workflows awkward. In particular, users bundling Lambda handlers to .mjs with tools like esbuild can hit dynamic require() issues, as described in #295.

This change keeps the existing CommonJS API working while adding a proper ESM build and package export map.

What Changed

  • Moves source files under src/ and builds published output into dist/cjs and dist/esm with SWC
  • Adds conditional package exports for both require() and import
  • Preserves supported deep imports like lambda-api/lib/utils
  • Adds SWC build configs for CJS and ESM output
  • Adds module compatibility tests covering:
    • CommonJS root import
    • CommonJS deep imports
    • ESM default import
    • ESM named/deep module imports
    • basic route execution from both builds

Why

This should make lambda-api friendlier for modern Lambda projects using ESM, .mjs entrypoints, or bundlers like esbuild, while remaining backwards compatible for existing CommonJS users.

@tomassabol tomassabol marked this pull request as ready for review June 16, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant