Skip to content

fix(esm): append .js extensions to relative and subpath imports#8594

Open
harshitanand wants to merge 1 commit intoBitGo:masterfrom
harshitanand:fix/issue-7660-esm-extensions
Open

fix(esm): append .js extensions to relative and subpath imports#8594
harshitanand wants to merge 1 commit intoBitGo:masterfrom
harshitanand:fix/issue-7660-esm-extensions

Conversation

@harshitanand
Copy link
Copy Markdown

What

Added a post-processor script to append .js extensions to ESM builds for @bitgo/abstract-utxo and @bitgo/utxo-core to fix module resolution errors.

How

Created a lightweight Node.js script scripts/fix-esm.js that finds import/export statements in the emitted dist/esm files and intelligently adds .js extensions to relative paths and specific bip174 subpaths without breaking existing CJS builds.

Testing

  • Existing tests pass
  • yarn build:esm — CLEAN
  • yarn test — 1942 passed, 0 failed

Related

Closes #7660

@harshitanand harshitanand requested review from a team as code owners April 22, 2026 00:39
Copy link
Copy Markdown
Contributor

@kaustubhbitgo kaustubhbitgo left a comment

Choose a reason for hiding this comment

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

From the original issue I would suggest to either use tsc-alias or bundler option as they cover multiple edge cases when it comes to resolve imports / other issues in esm.

@harshitanand
Copy link
Copy Markdown
Author

Thanks for the review! Understood — the custom post-processor is brittle compared to tsc-alias which handles the full range of ESM path-rewriting edge cases (barrel re-exports, conditional imports, declaration files, etc.).

Could you clarify which approach you'd prefer me to implement?

  1. tsc-alias — add as a dev dependency, run tsc-alias after tsc in the build:esm step (e.g. "build:esm": "tsc -p tsconfig.esm.json && tsc-alias -p tsconfig.esm.json")
  2. Bundler option — switch the ESM output to use a bundler (esbuild/rollup) that handles module resolution natively

Happy to implement either. tsc-alias is a minimal change with no bundler adoption overhead — I'll go that route unless you have a preference for the bundler approach.

@alextse-bg
Copy link
Copy Markdown
Contributor

flushing, please reping when the fix is ready

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.

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

3 participants