Skip to content

Add dual module support (ESM + CommonJS) #61

@jariy17

Description

@jariy17

Summary

Add support for both ESM and CommonJS module systems to improve compatibility with projects using CommonJS resolution (e.g., tsx with CommonJS projects).

Background

Currently, this package is ESM-only ("type": "module"). Users with CommonJS projects encounter module resolution errors when trying to import this package.

Related: #42, PR #43

Proposed Solution

Implement dual module support following the AWS SDK pattern:

  1. Separate build outputs: dist-cjs/ (CommonJS) and dist-es/ (ESM)
  2. Update package.json exports:
    "exports": {
      ".": {
        "require": "./dist-cjs/index.js",
        "import": "./dist-es/index.js",
        "types": "./dist-types/index.d.ts"
      }
    }
  3. Add separate TypeScript configs for each module format

Alternatives Considered

  • Bundler approach (tsup/esbuild): Single config generates both formats
  • Keep ESM-only: Document requirement for users to configure their projects for ESM

Current Workaround

Users can add "type": "module" to their project's package.json to enable ESM resolution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions