[v22.x backport] fs: restore fs patchability in ESM loader#64722
Open
ash2228 wants to merge 1 commit into
Open
[v22.x backport] fs: restore fs patchability in ESM loader#64722ash2228 wants to merge 1 commit into
ash2228 wants to merge 1 commit into
Conversation
Temporarily restore fs patchability in ESM loader as a workaround for helping downstream projects that depend on this undocumented hidden contract transition into using hook proper APIs. This patch intentionally avoids adding a test and instead adds warning comments to hopefully steer new code away from depending on it. PR-URL: nodejs#62835 Refs: nodejs#62012 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> (cherry picked from commit 9531947)
Collaborator
|
Review requested:
|
avivkeller
approved these changes
Jul 25, 2026
avivkeller
left a comment
Member
There was a problem hiding this comment.
While intentionally adding a thing we don't recommend is odd to me, LGTM to unbreak consumers
This comment was marked as outdated.
This comment was marked as outdated.
Contributor
Collaborator
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.
Backport of #62835 to the v22.x line.
#62835 landed on
mainin 9531947 and was backported to v26.x (v26.1.0)and v24.x (v24.16.0), but not to v22.x. It did not cherry-pick cleanly onto
v22 —
lib/internal/modules/esm/load.jsconflicted, which is likely why itwas missed.
This fixes #64709. Under Yarn PnP on v22.22.3 through v22.23.1, the ESM
loader captures
readFileSync/realpathSyncbefore PnP patchesfs, soNode cannot read sources from the zip cache itself. PnP supplies the source
through its load hook instead, which routes loading through the synthetic
require in
loadCJSModule— that one does not setcacheorextensions.Result:
rechoir/webpack-cliandimport-fresh/postcss-loaderbothbreak.
Conflict resolution: v22's
load.jsalso importsgetOptionValuefor--experimental-default-type, which does not exist on the newer lines. Thatimport is preserved; only the
fsimport and call sites changed. The restThe rest applied cleanly from 9531947.
The v22 build is still compiling locally, so I haven't yet run the
reproducer against a patched binary — I'll follow up with before/after
output. Opening now so it's visible in case someone wants to pick it up
sooner.