Skip to content

Commit

Permalink
fix NODE_OPTIONS env forwarding (#11587)
Browse files Browse the repository at this point in the history
I got this error when executing `Run Dev Server` on the VScode

```
api | Waiting for the debugger to disconnect...
api | node:events:497
api |       throw er; // Unhandled 'error' event
api |       ^
api | 
api | Error: spawn Studio 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 Studio',
api |   path: 'Studio',
api |   spawnargs: [
api |     'Code.app/Contents/Resources/app/extensions/ms-vscode.js-debug/src/bootloader.js  --inspect-publish-uid=http --enable-source-maps',
api |     'yarn',
api |     'nodemon',
api |     '--quiet',
api |     '--watch',
api |     '/Users/tim/Workspace/src/github.com/daangn/activity-badge-admin/redwood.toml',
api |     '--exec',
api |     'yarn rw-api-server-watch       --port 8911       --debug-port 18911       | rw-log-formatter'
api |   ]
api | }
```

Because the VSCode debugger injects this env variable,

```
 --require "/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.js-debug/src/bootloader.js"  --inspect-publish-uid=http
```

But not escaped correctly

```
yarn cross-env NODE_ENV=development NODE_OPTIONS="--require "/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.js-debug/src/bootloader.js"  --inspect-publish-uid=http --enable-source-maps"   yarn nodemon     --quiet     --watch "/Users/tim/Workspace/src/github.com/daangn/activity-badge-admin/redwood.toml"     --exec "yarn rw-api-server-watch       --port 8911       --debug-port 18911       | rw-log-formatter" exited with code 1
```

---------

Co-authored-by: Josh GM Walker <[email protected]>
  • Loading branch information
cometkim and Josh-Walker-GM authored Sep 24, 2024
1 parent 3a2169b commit 6cc6e51
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
36 changes: 36 additions & 0 deletions .changesets/11587.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 6 additions & 2 deletions packages/cli/src/commands/__tests__/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down Expand Up @@ -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')
})
Expand Down
19 changes: 11 additions & 8 deletions packages/cli/src/commands/devHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down

0 comments on commit 6cc6e51

Please sign in to comment.