Skip to content

Added support for es6#471

Open
ankitdas13 wants to merge 2 commits into
masterfrom
feat/es6-support
Open

Added support for es6#471
ankitdas13 wants to merge 2 commits into
masterfrom
feat/es6-support

Conversation

@ankitdas13
Copy link
Copy Markdown
Contributor

@ankitdas13 ankitdas13 commented May 6, 2026

feat: add ESM support with dual CJS/ESM build (v3.0.0)

What

Adds native ES6 / ESM support to the Razorpay Node SDK while maintaining full backward compatibility with existing CommonJS users.

Why

The SDK previously only shipped a CommonJS build (dist/razorpay.js). Consumers using import Razorpay from 'razorpay' in ESM projects, modern bundlers (Vite, Rollup), or TypeScript with "module": "ESNext" had no native ESM entry point.

Changes

Build system

  • Replaced Babel (babel-cli, babel-preset-env, babel-preset-stage-0) with tsup for a faster, modern dual-format.

build

  • Added tsup.config.ts — produces three build targets:
    • dist/razorpay.mjs — ESM build
    • dist/razorpay.js — CJS build (with module.exports unwrap for zero breaking changes)
    • dist/oAuthTokenClient.js, dist/utils/* — CJS utility modules

package.json

  • Added "module": "dist/razorpay.mjs" for bundler resolution
  • Added "exports" field with conditional import / require / types paths
  • Added subpath exports for all deep imports (dist/oAuthTokenClient, dist/utils/razorpay-utils, dist/types/*) to preserve backward compatibility
  • Upgraded typescript from ^4.9.4 → ^5.9.3
  • Removed unused Babel devDependencies; added tsup: ^8.5.1
  • Fixed cp-types script (mkdir -p, corrected *.d.ts glob)

Backword compatible

Import style Before After
require('razorpay')
import Razorpay from 'razorpay'
require('razorpay/dist/oAuthTokenClient')
require('razorpay/dist/utils/razorpay-utils')
import { Orders } from 'razorpay/dist/types/orders'

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