diff --git a/.changesets/11587.md b/.changesets/11587.md new file mode 100644 index 000000000000..b84c5b369503 --- /dev/null +++ b/.changesets/11587.md @@ -0,0 +1,36 @@ +- fix `NODE_OPTIONS` env forwarding (#11587) by @cometkim + +This change updates how we pass through any `NODE_OPTIONS` when you run the API side development server with `yarn rw dev`. Previously there may have been issues like unescaped spaces in paths which would have produced errors like: + +``` +api | node:events:497 +api | throw er; // Unhandled 'error' event +api | ^ +api | +api | Error: spawn space.js --enable-source-maps ENOENT +api | at ChildProcess._handle.onexit (node:internal/child_process:286:19) +api | at onErrorNT (node:internal/child_process:484:16) +api | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) +api | Emitted 'error' event on ChildProcess instance at: +api | at ChildProcess._handle.onexit (node:internal/child_process:292:12) +api | at onErrorNT (node:internal/child_process:484:16) +api | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { +api | errno: -2, +api | code: 'ENOENT', +api | syscall: 'spawn space.js --enable-source-maps', +api | path: 'space.js --enable-source-maps', +api | spawnargs: [ +api | 'yarn', +api | 'nodemon', +api | '--quiet', +api | '--watch', +api | '/Users/jgmw/Development/redwood/rw-test/node_options_fix/redwood.toml', +api | '--exec', +api | 'yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter' +api | ] +api | } +api | +api | Node.js v20.17.0 +``` + +Now these sort of error should no longer occur. diff --git a/packages/cli/src/commands/__tests__/dev.test.js b/packages/cli/src/commands/__tests__/dev.test.js index bed9dfcf7fb3..ad5b0c3e571a 100644 --- a/packages/cli/src/commands/__tests__/dev.test.js +++ b/packages/cli/src/commands/__tests__/dev.test.js @@ -121,8 +121,10 @@ describe('yarn rw dev', () => { // test environments (vite sets this in their vite-ecosystem-ci tests) .replace(/--max-old-space-size=\d+\s/, ''), ).toEqual( - 'yarn cross-env NODE_ENV=development NODE_OPTIONS="--enable-source-maps" yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter"', + 'yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter"', ) + expect(apiCommand.env.NODE_ENV).toEqual('development') + expect(apiCommand.env.NODE_OPTIONS).toContain('--enable-source-maps') expect(generateCommand.command).toEqual('yarn rw-gen-watch') }) @@ -166,8 +168,10 @@ describe('yarn rw dev', () => { // test environments (vite sets this in their vite-ecosystem-ci tests) .replace(/--max-old-space-size=\d+\s/, ''), ).toEqual( - 'yarn cross-env NODE_ENV=development NODE_OPTIONS="--enable-source-maps" yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter"', + 'yarn nodemon --quiet --watch "/mocked/project/redwood.toml" --exec "yarn rw-api-server-watch --port 8911 --debug-port 18911 | rw-log-formatter"', ) + expect(apiCommand.env.NODE_ENV).toEqual('development') + expect(apiCommand.env.NODE_OPTIONS).toContain('--enable-source-maps') expect(generateCommand.command).toEqual('yarn rw-gen-watch') }) diff --git a/packages/cli/src/commands/devHandler.js b/packages/cli/src/commands/devHandler.js index 90f31950a23a..3934460ef2f4 100644 --- a/packages/cli/src/commands/devHandler.js +++ b/packages/cli/src/commands/devHandler.js @@ -179,15 +179,18 @@ export const handler = async ({ api: { name: 'api', command: [ - `yarn cross-env NODE_ENV=development NODE_OPTIONS="${getDevNodeOptions()}"`, - ' yarn nodemon', - ' --quiet', - ` --watch "${redwoodConfigPath}"`, - ' --exec "yarn rw-api-server-watch', - ` --port ${apiAvailablePort}`, - ` ${getApiDebugFlag()}`, - ' | rw-log-formatter"', + 'yarn nodemon', + ' --quiet', + ` --watch "${redwoodConfigPath}"`, + ' --exec "yarn rw-api-server-watch', + ` --port ${apiAvailablePort}`, + ` ${getApiDebugFlag()}`, + ' | rw-log-formatter"', ].join(' '), + env: { + NODE_ENV: 'development', + NODE_OPTIONS: getDevNodeOptions(), + }, prefixColor: 'cyan', runWhen: () => fs.existsSync(rwjsPaths.api.src), },