Skip to content

fix(arborist): expose store node_modules via NODE_PATH for linked-strategy install scripts#9551

Merged
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-script-node-path-9549
Jun 18, 2026
Merged

fix(arborist): expose store node_modules via NODE_PATH for linked-strategy install scripts#9551
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-script-node-path-9549

Conversation

@manzoorwanijk

@manzoorwanijk manzoorwanijk commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

In continuation of our exploration of using install-strategy=linked in the Gutenberg monorepo, which powers the WordPress Block Editor.

Under install-strategy=linked, a package whose install script invokes a separate helper bin to locate a native binding fails (e.g. unrs-resolver via napi-postinstall, and the wider napi-postinstall family). The helper bin is reached via a .bin symlink, so Node resolves it to its own realpath in its own store dir, from which it can't require.resolve the host's binding — so it declares it missing and re-downloads (fatal on a restricted registry/proxy). Hoisted works because the binding is hoisted onto the helper's resolution path.

How

When running a store node's lifecycle script, set NODE_PATH to the host package's store node_modules so a script-invoked bin can resolve the host's sibling deps:

if (isInStore) {
  const storeNodeModules = resolve(path, ...name.split('/').map(() => '..'))
  env.NODE_PATH = [storeNodeModules, process.env.NODE_PATH].filter(Boolean).join(delimiter)
}

NODE_PATH is fallback-only (can't shadow working resolution), added only to the script's env (never process.env), and scoped to the store-local node_modules — install-time only, runtime isolation untouched.

References

Fixes #9549

@manzoorwanijk manzoorwanijk force-pushed the fix/linked-script-node-path-9549 branch from 1ed9016 to afa52bd Compare June 13, 2026 10:42
@manzoorwanijk manzoorwanijk marked this pull request as ready for review June 13, 2026 10:54
@manzoorwanijk manzoorwanijk requested review from a team as code owners June 13, 2026 10:54
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-script-node-path-9549 branch from afa52bd to 0e62a20 Compare June 18, 2026 14:28
@owlstronaut owlstronaut merged commit afce424 into npm:latest Jun 18, 2026
25 checks passed
@manzoorwanijk manzoorwanijk deleted the fix/linked-script-node-path-9549 branch June 18, 2026 21:16
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Backport to release/v11 created: #9578

owlstronaut pushed a commit that referenced this pull request Jun 18, 2026
…ategy install scripts (#9578)

Backport of #9551 to `release/v11`.

Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants