Skip to content

[v22.x backport] fs: restore fs patchability in ESM loader#64722

Open
ash2228 wants to merge 1 commit into
nodejs:v22.x-stagingfrom
ash2228:v22.x-backport-62835
Open

[v22.x backport] fs: restore fs patchability in ESM loader#64722
ash2228 wants to merge 1 commit into
nodejs:v22.x-stagingfrom
ash2228:v22.x-backport-62835

Conversation

@ash2228

@ash2228 ash2228 commented Jul 24, 2026

Copy link
Copy Markdown

Backport of #62835 to the v22.x line.

#62835 landed on main in 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.js conflicted, which is likely why it
was missed.

This fixes #64709. Under Yarn PnP on v22.22.3 through v22.23.1, the ESM
loader captures readFileSync/realpathSync before PnP patches fs, so
Node 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 set cache or extensions.
Result: rechoir/webpack-cli and import-fresh/postcss-loader both
break.

Conflict resolution: v22's load.js also imports getOptionValue for
--experimental-default-type, which does not exist on the newer lines. That
import is preserved; only the fs import and call sites changed. The rest
The 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.

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)
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. v22.x Issues that can be reproduced on v22.x or PRs targeting the v22.x-staging branch. labels Jul 24, 2026

@avivkeller avivkeller left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While intentionally adding a thing we don't recommend is odd to me, LGTM to unbreak consumers

@MikeMcC399
MikeMcC399 requested a review from joyeecheung July 25, 2026 06:20
@MikeMcC399 MikeMcC399 added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 25, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 25, 2026
@nodejs-github-bot

This comment was marked as outdated.

@MikeMcC399

Copy link
Copy Markdown
Contributor

@ash2228

Backporting #62835 on its own does not appear to resolve issue #64709

Did you test your change against the repro steps in #64709?

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. v22.x Issues that can be reproduced on v22.x or PRs targeting the v22.x-staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants