Skip to content

fix(esm): use tsc-alias to append .js extensions to ESM imports#8594

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

fix(esm): use tsc-alias to append .js extensions to ESM imports#8594
harshitanand wants to merge 1 commit intoBitGo:masterfrom
harshitanand:fix/issue-7660-esm-extensions

Conversation

@harshitanand
Copy link
Copy Markdown

@harshitanand harshitanand commented Apr 22, 2026

What

Fixes ESM module resolution errors in @bitgo/abstract-utxo and @bitgo/utxo-core by adding .js extensions to relative imports in compiled output.

How

Uses tsc-alias with fileExtensionReplacer — the standard, well-tested approach for this problem — instead of a custom post-processor script.

  • build:esm in both modules now runs tsc-alias -p tsconfig.esm.json after tsc
  • tsc-alias ^1.8.10 added to devDependencies in both modules
  • fileExtensionReplacer configured under the "tsc-alias" key in each module's package.json
  • scripts/fix-esm.js retired (file contains a comment pointing to the new approach)

tsc-alias handles barrel re-exports, declaration files, dynamic imports, and directory index resolution — all edge cases the custom script would have missed.

Testing

  • yarn build:esm — CLEAN (both modules)
  • 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

@harshitanand
Copy link
Copy Markdown
Author

@alextse-bg Fix is ready — switched from the custom fix-esm.js post-processor to tsc-alias as suggested (commit 34829a0).

What changed:

  • build:esm in both abstract-utxo and utxo-core now runs tsc-alias -p tsconfig.esm.json after tsc
  • tsc-alias added to devDependencies in both modules (^1.8.10)
  • fileExtensionReplacer configured in each module's package.json under the "tsc-alias" key — this appends .js to relative imports in the compiled ESM output, which is the canonical way to handle this
  • scripts/fix-esm.js retired (file now contains only a comment pointing to the new approach)

tsc-alias covers barrel re-exports, declaration files, dynamic imports, and all the edge cases the custom script missed. Ready for re-review.

@harshitanand harshitanand changed the title fix(esm): append .js extensions to relative and subpath imports fix(esm): use tsc-alias to append .js extensions to ESM imports Apr 30, 2026
@harshitanand
Copy link
Copy Markdown
Author

@alextse-bg Rebased onto latest master (53f2bea) — picked up the version bumps in abstract-utxo (10.23.1→10.24.0) and utxo-core (1.36.0→1.36.1) and updated dependency versions. The tsc-alias changes are intact. Also updated the PR description to reflect the current implementation. Ready for re-review.

@harshitanand
Copy link
Copy Markdown
Author

@alextse-bg Rebased onto current master (e385447) — conflict resolved, tsc-alias changes intact (54a39e9). Ready for re-review.

@harshitanand harshitanand force-pushed the fix/issue-7660-esm-extensions branch from 54a39e9 to 48640cf Compare May 1, 2026 08:31
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