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.

@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

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@MikeMcC399

MikeMcC399 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

I have not managed to get a successful Jenkins run so far, however there have been general problems this week, so I would wait until the security release has gone out before coming back to this PR.

@ash2228

ash2228 commented Jul 29, 2026

Copy link
Copy Markdown
Author

Thanks for the update, I'll wait until the security release is out and then revisit this PR. Appreciate you taking a look.

@MikeMcC399

Copy link
Copy Markdown
Contributor

nodejs/citgm#1112 shows Yarn 4.18.0 failing in CITGM tests (without this PR). It's possible that there are multiple issues contributing to failure.

@marco-ippolito
marco-ippolito requested a review from a team as a code owner July 29, 2026 13:35
@MikeMcC399

This comment was marked as resolved.

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)
@ash2228
ash2228 force-pushed the v22.x-backport-62835 branch from 40e2961 to 7dd23a7 Compare July 29, 2026 14:16
@ash2228

ash2228 commented Jul 29, 2026

Copy link
Copy Markdown
Author

Thanks, I rebased the PR onto the latest v22.x-staging (currently based on 400e833). Let me know if there's anything else I should update.

@MikeMcC399 MikeMcC399 added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 29, 2026
@github-actions github-actions Bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jul 29, 2026
@github-actions

This comment was marked as outdated.

@MikeMcC399 MikeMcC399 added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 29, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 29, 2026
@nodejs-github-bot

This comment was marked as outdated.

@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. request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. 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