From d886d5f2954843c20a4710cf66aa3b020ea2f806 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Sat, 25 Jul 2020 19:57:01 -0400 Subject: [PATCH] feat: use `process.env.METRO_NODE_OPTIONS` when starting Metro Instead of using NODE_OPTIONS from the expo-cli process, the Metro process overrides it with METRO_NODE_OPTIONS. This has two effects: (1) the expo-cli process can be debugged with --inspect-brk without causing an "address already in use" error in the Metro process, and (2) the Metro process can be debugged with --inspect-brk. --- packages/xdl/src/Project.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/xdl/src/Project.ts b/packages/xdl/src/Project.ts index 051fabf1e7..2cb1fe2b33 100644 --- a/packages/xdl/src/Project.ts +++ b/packages/xdl/src/Project.ts @@ -1796,9 +1796,12 @@ export async function startReactNativeServerAsync( if (options.reset) { cliOpts.push('--reset-cache'); - } // Get custom CLI path from project package.json, but fall back to node_module path + } + + // Get custom CLI path from project package.json, but fall back to node_module path const defaultCliPath = resolveModule('react-native/local-cli/cli.js', projectRoot, exp); const cliPath = exp.rnCliPath || defaultCliPath; + let nodePath; // When using a custom path for the RN CLI, we want it to use the project // root to look up config files and Node modules @@ -1807,15 +1810,18 @@ export async function startReactNativeServerAsync( } else { nodePath = null; } + // Run the copy of Node that's embedded in Electron by setting the // ELECTRON_RUN_AS_NODE environment variable // Note: the CLI script sets up graceful-fs and sets ulimit to 4096 in the // child process const nodePathEnv = nodePath ? { NODE_PATH: nodePath } : {}; + const packagerProcess = child_process.fork(cliPath, cliOpts, { cwd: projectRoot, env: { ...process.env, + NODE_OPTIONS: process.env.METRO_NODE_OPTIONS, REACT_NATIVE_APP_ROOT: projectRoot, ELECTRON_RUN_AS_NODE: '1', ...nodePathEnv,