fix: resolve CommonJS directory requires inside dependencies#803
Merged
privatenumber merged 2 commits intoMay 31, 2026
Merged
Conversation
torbjornvatn
added a commit
to torbjornvatn/tsx-json-bug
that referenced
this pull request
May 28, 2026
Replace statuses/JSON repro with superagent-based HTTP fetch so the test exercises tsx's CJS require() hook — the actual failure surface on Node 24 where tsx wrongly rewrites intra-node_modules relative paths (.js → .jsx/.ts etc.). - swap statuses → superagent (CJS pkg with internal require() calls) - src/status.ts: fetchJson() wraps superagent GET - src/status.test.ts: offline local http server, two JSON round-trips - add tsx-pr (file:../tsx-fix) — local build of PR #803 fix branch - add test:pr script; drop @types/statuses - update README to document new bug, fix, and all four test variants Refs privatenumber/tsx#800, privatenumber/tsx#803
Owner
|
Thanks for kicking this off, @imevanc! I pushed a commit that extends it to fix the underlying cause more broadly. The directory resolution was handing Node's CommonJS resolver a That also covers two related shapes from the same code path:
Added regression tests for each, and CI is green across the Node matrix. |
6 tasks
Owner
|
This issue is now resolved in v4.22.4. If you're able to, your sponsorship would be very much appreciated. |
1 task
5 tasks
1 task
This was referenced Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Node 24+, a CommonJS
require()inside a dependency flows through tsx's sync ESM hook, where directory-style specifiers (require('..'),require('process/')) were resolved to afile://URL. Node's CommonJS resolver rejectsfile://URLs in arequire()context, so every candidate failed — including the real.js/.ts— and the last-tried.jsxsurfaced:Changes
In a CommonJS
require()context,resolveDirectorySync:require('process/')) to Node's package resolution;require('..'),require('./dir/')) from a filesystem path, falling back to the directory'spackage.jsonmainwhen no index file exists.The ESM import path is unchanged.
Closes #800