fix(node): use fs.readFileSync in CJS module loader for monkey-patch compat#33210
Open
bartlomieju wants to merge 1 commit intomainfrom
Open
fix(node): use fs.readFileSync in CJS module loader for monkey-patch compat#33210bartlomieju wants to merge 1 commit intomainfrom
bartlomieju wants to merge 1 commit intomainfrom
Conversation
…compat Deno's CJS require system was using `op_require_read_file` (a direct Rust op) to read module source files, bypassing the `node:fs` module entirely. This broke tools like vue-tsc (@volar/typescript) that monkey-patch `fs.readFileSync` to intercept and transform source files during require(). Switch to `fs.readFileSync` in the CJS/JSON extension handlers so that monkey-patches are respected. Fall back to `op_require_read_file` for virtual files (like `$deno$eval.cjs`) that don't exist on disk. Closes #30977 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Member
Author
|
The CI failures are all CJS module loading regressions across every platform. The common pattern is that files requiring transpilation ( Failing tests:
Root cause: |
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.
Summary
op_require_read_file(a direct Rust op)to read module source files, bypassing the
node:fsmodule entirely. Thisbroke tools like
vue-tsc(@volar/typescript) that monkey-patchfs.readFileSyncto intercept and transform source files duringrequire().fs.readFileSyncin the CJS/JSON extension handlers so thatmonkey-patches are respected. Fall back to
op_require_read_filefor virtualfiles (like
$deno$eval.cjs) that don't exist on disk.Root cause
@volar/typescript'srunTsc()works by monkey-patchingfs.readFileSynctointercept reads of TypeScript's
tsc.jsand return a transformed version withVolar's
proxyCreatePrograminjected. Under Node.js this works because CJSModule._extensionshandlers usefs.readFileSyncto read source files. UnderDeno, the handlers used
op_require_read_filewhich goes directly to Rust,so the monkey-patch was never triggered and
tsc.jsran unmodified withoutVue SFC support.
Closes #30977
Test plan
require_fs_readfilesync_interceptverifies thatmonkey-patching
fs.readFileSyncis respected whenrequire()loads.cjsand.jsonfilesdual_cjs_esm, translate_cjs_to_esm, deno_run_cowsay, etc.)
deno evalwith CJS) still works via fallback🤖 Generated with Claude Code