fix(pnp): provide source for commonjs files inside zip archives#7086
Open
tellnes wants to merge 1 commit intoyarnpkg:masterfrom
Open
fix(pnp): provide source for commonjs files inside zip archives#7086tellnes wants to merge 1 commit intoyarnpkg:masterfrom
tellnes wants to merge 1 commit intoyarnpkg:masterfrom
Conversation
The ESM load hook returned undefined source for all CJS modules, which worked because Node falls back to reading the file itself. Node 25.7.0 changed this fallback to use getSourceSync(), which fails with EBADF on zip-internal paths since they aren't real filesystem entries. Source is now provided for CJS files inside zip archives while preserving the undefined return for local CJS files, which is needed for CJS monkey-patching compatibility.
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.
What's the problem this PR addresses?
The PnP ESM loader fails with
EBADF: bad file descriptor, fstaton Node.js >= 25.7.0 when ESM code imports a CommonJS package from a zip archive.Bisected results:
The regression was introduced by nodejs/node#61769 ("lib: reduce cycles in esm loader and load it in snapshot"), which changed how
createCJSModuleWraphandles null source. When the PnP loader returnsundefinedsource for CJS modules, Node's fallback now callsgetSourceSync()which tries toreadFileSyncthe zip-internal path and fails.Error:
How did you fix it?
For CommonJS files inside zip archives (
.zip/in path), the PnPloadhook now returns the source content instead ofundefined. This prevents Node from trying to read the file from disk.For CJS files on the real filesystem,
undefinedis still returned to preserve the CJS monkey-patching behavior (cf. #5677).Checklist