fix(core): strip package map option for external files in shims - #7252
Open
Ayush442842q wants to merge 1 commit into
Open
fix(core): strip package map option for external files in shims#7252Ayush442842q wants to merge 1 commit into
Ayush442842q wants to merge 1 commit into
Conversation
Ayush442842q
force-pushed
the
fix-yarn-issue-7210
branch
from
August 9, 2026 22:01
d5c9fb6 to
357efbd
Compare
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?
When
nodeExperimentalPackageMapis enabled (withnodeLinker: pnpmornode-modules), Yarn injects--experimental-package-mapintoNODE_OPTIONS. BecauseNODE_OPTIONSis recursively inherited by child processes, this causes global or external Node.js tools spawned during script execution (such ascorepack,npm,npx, etc.) to run with the package map enabled.Since Node's native package map implementation strictly checks if the importing file belongs to a package defined in
package-map.json, any import of bare specifiers by these external/global tools throws a fatalERR_PACKAGE_MAP_EXTERNAL_FILEerror (since they reside outside the local project).Resolves #7210.
How did you fix it?
We scope-limit the package map resolution so that it only applies to Node.js executions that run scripts within the project root directory.
node-wrapper.js): Generated dynamically inside the script temporary binary execution directory (binFolder).BERRY_PROJECT_ROOTenvironment variable), or if it is running a global tool, it strips--experimental-package-mapfromNODE_OPTIONSbefore spawning the realnodebinary.makePathWrapperso that shims created for Node.js (node,yarn,yarnpkg,run,node-gyp) route their execution through this proxy.This ensures that the project's own files and dependencies are resolved using the package map, while global tools run safely using standard resolution.
Checklist