fix(tui): map .js imports to .ts sources in esbuild bundle - #56543
fix(tui): map .js imports to .ts sources in esbuild bundle#56543DeviStormrage wants to merge 1 commit into
Conversation
tsconfig uses moduleResolution: nodenext, which requires every relative import to spell the .js extension (even when the file on disk is .ts or .tsx). esbuild does not auto-rewrite .js -> .ts for imports that already carry an explicit extension — it only walks resolveExtensions for extensionless imports. Without a resolver plugin, every `import x from "../lib/foo.js"` fails to resolve even though foo.ts is right there, and `hermes --tui` rebuilds fail on the first launch with "Could not resolve ../lib/foo.js". Add a small esbuild plugin that maps .js -> .tsx/.ts/.jsx/.js on disk and lets esbuild pick up the match.
|
Thanks for the focused TUI build fix. I found no verified blocker. Current main still has NodeNext The existing bundle regression test already invokes Automated hermes-sweeper review. |
What does this PR do?
Adds an esbuild resolver plugin to
ui-tui/scripts/build.mjsthat maps.jsimport paths to.ts/.tsx/.jsxsource files on disk. Fixes thehermes --tuirebuild failure on first launch.Related Issue
The TUI build script (
scripts/build.mjs) uses esbuild without a resolver plugin. Combined withui-tui/tsconfig.jsonadoptingmoduleResolution: "nodenext"(which requires every relative import to spell the.jsextension even when the file on disk is.ts/.tsx), this means the first launch on any user install fails with errors like:The user has to manually patch the build script before the TUI can start. This PR adds the missing esbuild plugin so the build script works with the existing nodenext module resolution.
Related closed issue: #31227 (different root cause — async
__esmdeadlock — but adjacent area)Type of Change
Changes Made
ui-tui/scripts/build.mjs: addjsToTsPluginesbuild resolver plugin (32 lines including doc comment) and register it in thepluginsarray.The plugin:
.js.tsx,.ts,.jsxextensions on disk in ordernullto fall through to esbuild's default resolution for real.jsfiles (e.g. innode_modules/)How to Test
ui-tui/dist/entry.js(or test on a clean install)hermes --tuidist/entry.jsis producedVerified on: Windows 11 ARM64 (Snapdragon X Plus), Node.js 22, esbuild 0.28.x. The
jsToTsPluginis platform-agnostic — runs in esbuild on Linux, macOS, Windows alike.Checklist
Code
fix(tui): map .js imports to .ts sources in esbuild bundle)pytest tests/ -q— N/A (no Python changes)Documentation & Housekeeping
Screenshots / Logs
Before (clean install, first
hermes --tui):After (same clean install):
TUI launches and runs as expected.