JS/TS Runtime Compatibility
Runtime targets
- Node.js 18+
- Node.js 20+
- Node.js 22+
- Modern ESM bundlers
Module format support
- ESM (
import) - CJS (
require) - TypeScript declarations for public exports
ESM example
What this does: imports canonical SDK in modern Node/bundlers.
import { createClient } from '@pepay/x402flex';
const sdk = createClient({
mode: 'api',
api: { baseUrl: 'https://api.bnbpay.org' },
});
Expected result: full typed SDK access in ESM modules.
CJS example
What this does: uses canonical package from CommonJS runtime.
const { createClient } = require('@pepay/x402flex');
const sdk = createClient({
mode: 'api',
api: { baseUrl: 'https://api.bnbpay.org' },
});
Expected result: compatible CJS import path.
TypeScript example
What this does: uses typed subpath imports.
import { createClient } from '@pepay/x402flex';
import { wrapFetchWithPayment } from '@pepay/x402flex/fetch';
import { wrapAxiosWithPayment } from '@pepay/x402flex/axios';
const sdk = createClient({ mode: 'hybrid', preset: 'bnbpay-testnets', api: { baseUrl: 'https://api.bnbpay.org' } });
Expected result: compile-time type safety for top-level and subpath exports.
Common import issues
Cannot find modulein CJS: ensure package is installed in runtime workspace.- Default import mistakes: use named imports from package exports.