Skip to content

fix(core): strip package map option for external files in shims - #7252

Open
Ayush442842q wants to merge 1 commit into
yarnpkg:masterfrom
Ayush442842q:fix-yarn-issue-7210
Open

fix(core): strip package map option for external files in shims#7252
Ayush442842q wants to merge 1 commit into
yarnpkg:masterfrom
Ayush442842q:fix-yarn-issue-7210

Conversation

@Ayush442842q

@Ayush442842q Ayush442842q commented Aug 9, 2026

Copy link
Copy Markdown

What's the problem this PR addresses?

When nodeExperimentalPackageMap is enabled (with nodeLinker: pnpm or node-modules), Yarn injects --experimental-package-map into NODE_OPTIONS. Because NODE_OPTIONS is recursively inherited by child processes, this causes global or external Node.js tools spawned during script execution (such as corepack, 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 fatal ERR_PACKAGE_MAP_EXTERNAL_FILE error (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.

  1. Proxy Wrapper (node-wrapper.js): Generated dynamically inside the script temporary binary execution directory (binFolder).
  2. Arguments & Path Checking: When a Node execution is routed through this proxy:
    • It parses the execution arguments to check if a target script file is run.
    • If the script file resides outside the project root directory (by comparing against the BERRY_PROJECT_ROOT environment variable), or if it is running a global tool, it strips --experimental-package-map from NODE_OPTIONS before spawning the real node binary.
  3. Shim Routing: Modified makePathWrapper so 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

  • I will check that all automated PR checks pass before the PR gets reviewed.
  • I have set the packages that need to be released for my changes to be effective.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug?]: nodeExperimentalPackageMap + corepack

1 participant