Skip to content

Add ESM-first dual module support#226

Draft
jamiecobbett wants to merge 2 commits intotemplate-changesfrom
esm-support
Draft

Add ESM-first dual module support#226
jamiecobbett wants to merge 2 commits intotemplate-changesfrom
esm-support

Conversation

@jamiecobbett
Copy link
Contributor

This change adds full ES Module support while maintaining backward compatibility with CommonJS.

Key Changes:

  • Package is now "type": "module" with ESM as primary format
  • Dual compilation: ESM (dist/esm/) and CJS (dist/cjs/)
  • Package.json exports map for conditional resolution
  • Updated all imports to include .js extensions for ESM compatibility

Module Support:

  • ESM: import gocardless from 'gocardless-nodejs'
  • CJS: const gocardless = require('gocardless-nodejs')
  • Subpath exports: import { parse } from 'gocardless-nodejs/webhooks'
  • TypeScript types for both formats
  • Tree-shaking support for modern bundlers

Build Output:

  • dist/esm/ - ES Modules (primary)
  • dist/cjs/ - CommonJS (compatibility layer)
  • dist/types/ - Shared TypeScript definitions

Fixes #124

jamiecobbett and others added 2 commits January 23, 2026 15:36
This change adds full ES Module support while maintaining backward
compatibility with CommonJS.

Key Changes:
- Package is now "type": "module" with ESM as primary format
- Dual compilation: ESM (dist/esm/) and CJS (dist/cjs/)
- Package.json exports map for conditional resolution
- Updated all imports to include .js extensions for ESM compatibility

Module Support:
- ESM: import gocardless from 'gocardless-nodejs'
- CJS: const gocardless = require('gocardless-nodejs')
- Subpath exports: import { parse } from 'gocardless-nodejs/webhooks'
- TypeScript types for both formats
- Tree-shaking support for modern bundlers

Build Output:
- dist/esm/ - ES Modules (primary)
- dist/cjs/ - CommonJS (compatibility layer)
- dist/types/ - Shared TypeScript definitions

Fixes #124

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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