Skip to content

Builds that set NODE_OPTIONS fail on macOS because Electron ignores it in the app's Node children #525

Closed

Description

@juanmaguitar

What happens

On macOS, "Apply and rebuild" on an older Gutenberg pull request (reproduced with gutenberg#76292, based on March 2026 trunk) fails with:

Build failed: Command failed: npm run --if-present --workspaces --silent build

--silent hides the real error. Without it, @wordpress/theme's build:tokens fails:

[ERROR:electron/shell/app/node_main.cc:153] Node.js environment variables are disabled because this process is invoked by other apps.
✗  [config] Cannot find module '.../packages/theme/bin/terrazzo-plugin-mode-overrides/index'

Why

  • That script runs cross-env NODE_OPTIONS=--import=esbuild-esm-loader/register tz build --config terrazzo.config.ts, so tz needs the --import to load a .ts config.
  • tz starts through our node shim, a bash script that execs the app binary with ELECTRON_RUN_AS_NODE=1.
  • On macOS, Electron ignores NODE_OPTIONS when the process was launched by something outside the app. Its parent here is bash, so the --import is dropped.

Scope

Proposed fix

On macOS, the node shim passes the incoming NODE_OPTIONS as CLI flags ahead of the script. Checked by hand on a copy of the site: with $NODE_OPTIONS before "$@" in the shim, the same build exits 0. Quoting inside NODE_OPTIONS needs care, plus tests in tests/unit/node-shims.test.cjs.

Found while testing #524.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: build-installnpm install, builds, the dev serverbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions