Skip to content

Conversation

@ananth99
Copy link
Contributor

@ananth99 ananth99 commented Dec 3, 2025

Ticket: SCAAS-2084

Summary

  • Add dual CJS/ESM build to @bitgo/sdk-core to enable Turbopack compatibility in Next.js(bitgo-ui)
  • Follows the same pattern as @bitgo/utxo-core (commit 36c3cd47)
  • Fixes issue where Turbopack fails to load WASM modules from @bitgo/wasm-utxo due to CJS-only exports
  • Slack thread reference: https://bitgo.slack.com/archives/C04LYHERBMF/p1764688935096539

Changes

  • tsconfig.esm.json (new): ESM build configuration with module: ES2020 and moduleResolution: bundler
  • tsconfig.json: Updated to output to dist/cjs with module: node16
  • package.json: Added module, browser, and conditional exports fields for dual build
  • eddsa.ts: Fixed lodash import syntax for ESM compatibility

Backward Compatibility

These changes are backward compatible:

  • require('@bitgo/sdk-core') still works (routes to CJS)
  • import from '@bitgo/sdk-core' now uses ESM
  • Types are preserved for both formats

Add dual CJS/ESM build to enable Turbopack compatibility.

- Add tsconfig.esm.json for ES module build
- Update tsconfig.json to output to dist/cjs
- Add conditional exports and module field in package.json
- Fix lodash import syntax for ESM compatibility

SCAAS-2084
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds dual CJS/ESM build support to @bitgo/sdk-core, following the established pattern from @bitgo/utxo-core. This enables compatibility with Next.js Turbopack by providing proper ESM exports while maintaining backward compatibility with existing CommonJS consumers. The changes address an issue where Turbopack fails to load WASM modules from @bitgo/wasm-utxo due to CJS-only exports.

Key Changes:

  • Implemented dual build system with separate TypeScript configurations for CJS (node16) and ESM (ES2020) outputs
  • Updated package.json with conditional exports, module, and browser fields for proper module resolution
  • Fixed lodash import syntax from TypeScript-specific require to standard ES6 import for ESM compatibility

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
modules/sdk-core/tsconfig.json Updated CJS build to output to dist/cjs with module: node16 and moduleResolution: node16
modules/sdk-core/tsconfig.esm.json New ESM build configuration with module: ES2020, moduleResolution: bundler, and output to dist/esm
modules/sdk-core/src/bitgo/tss/eddsa/eddsa.ts Changed lodash import from import _ = require('lodash') to import _ from 'lodash' for ESM compatibility
modules/sdk-core/package.json Added dual build scripts, conditional exports, and updated entry points to support both CJS and ESM consumers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ananth99 ananth99 marked this pull request as ready for review December 3, 2025 14:08
@ananth99 ananth99 requested review from a team as code owners December 3, 2025 14:08
@ananth99 ananth99 merged commit 86df81e into master Dec 4, 2025
20 checks passed
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.

4 participants