Skip to content

[Bug] ESM builds missing .js extensions in @bitgo/abstract-utxo (>=10.7.0) and @bitgo/utxo-core (>=1.24.0) #7660

@jakubswierczek

Description

@jakubswierczek

Environment Details

  • OS: macOS / Linux (Docker)
  • Node Version: 22.14+
  • Package Manager: pnpm 10.17.1
  • BitGoJS Version: @bitgo/abstract-utxo@10.8.0, @bitgo/utxo-core@1.25.0
  • BitGo Environment: Both testnet and mainnet

Expected Behavior

ESM builds in dist/esm/ should use proper Node.js ESM-compatible imports with explicit .js file extensions for relative imports, allowing the packages to be consumed in ESM projects.

Current Behavior

ESM builds use relative imports without .js extensions, causing ERR_MODULE_NOT_FOUND errors when importing the packages in Node.js ESM environments.

Error 1 (@bitgo/abstract-utxo):

Error [ERR_MODULE_NOT_FOUND]: Cannot find module
'/app/node_modules/@bitgo/abstract-utxo/dist/esm/abstractUtxoCoin'
imported from '/app/node_modules/@bitgo/abstract-utxo/dist/esm/index.js'

Error 2 (@bitgo/utxo-core):

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'bip174/src/lib/utils'
imported from '/app/node_modules/@bitgo/utxo-core/dist/esm/paygo/psbt/payGoAddressProof.js'

Possible Solution

The TypeScript compilation for ESM output needs to add .js extensions to all relative imports. This can be achieved by:

  1. Using tsc-alias or tsconfig-paths post-processing
  2. Setting moduleResolution: "NodeNext" with proper TypeScript configuration
  3. Using a bundler plugin like rollup-plugin-add-import-extension

Example of broken vs fixed imports:

// Current (broken)
export * from './abstractUtxoCoin';
import { foo } from './address';
import { checkForOutput } from 'bip174/src/lib/utils';

// Expected (fixed)
export * from './abstractUtxoCoin.js';
import { foo } from './address/index.js';
import { checkForOutput } from 'bip174/src/lib/utils.js';

Steps to Reproduce

  1. Create an ESM Node.js project ("type": "module" in package.json)
  2. Install @bitgo/sdk-coin-zec@2.6.0 (which depends on @bitgo/abstract-utxo@10.8.0)
  3. Import the package:
    import { Zec } from '@bitgo/sdk-coin-zec';
  4. Run with Node.js 22+:
    node index.js
  5. Observe ERR_MODULE_NOT_FOUND error

Affected Versions

Package Last Working Broken
@bitgo/abstract-utxo 10.6.0 (CJS only) >=10.7.0 (ESM introduced)
@bitgo/utxo-core 1.23.0 (CJS only) >=1.24.0 (ESM introduced)

Workaround

We are currently using pnpm patches to add .js extensions to all ESM imports:

{
  "pnpm": {
    "patchedDependencies": {
      "@bitgo/abstract-utxo@10.8.0": "patches/@bitgo__abstract-utxo@10.8.0.patch",
      "@bitgo/utxo-core@1.25.0": "patches/@bitgo__utxo-core@1.25.0.patch"
    }
  }
}

This is not sustainable as patches need to be regenerated for each version upgrade.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions