Skip to content

fix: resolve relative commands with custom cwd in Worker threads - #183

Open
vhinayindia wants to merge 1 commit into
moxystudio:masterfrom
vhinayindia:fix/worker-relative-shebang-cwd
Open

vhinayindia wants to merge 1 commit into
moxystudio:masterfrom
vhinayindia:fix/worker-relative-shebang-cwd

Conversation

@vhinayindia

Copy link
Copy Markdown

On Windows, process.chdir() is unavailable inside Worker threads. When spawn receives an explicit relative command such as ./fixtures/shebang and a custom cwd, which.sync() resolves the command from the parent process working directory, so the spawn fails with ENOENT.

Resolve explicit relative paths against the requested child cwd when cwd switching is unavailable. Bare command names continue to resolve through PATH.

Validation:

  • npm run lint — passed.
  • npm test -- --runInBand --testNamePattern='^(?!.*should NOT spawn a shell for a \.exe)' — 77 passed, 2 skipped.
  • npm test -- --runInBand — 77 passed, 2 failed. The same two .exe fixture tests fail at baseline because win-ppid.js relies on wmic, which is unavailable in this environment.

@Timbic

Timbic commented Oct 24, 2026 •

Copy link
Copy Markdown

Hi @vhinayindia !!!
Thanks for tracking down and fixing this. Relying on process.chdir() in Worker threads is a nasty edge case on Windows.

Sadly this package is no longer mantained be the creator, but if you are interested, I ported your fix to cross-spawn-esm, my ESM/TypeScript drop-in replacement for cross-spawn. Our implementation already avoids process.chdir() entirely, so we weren't hit by this bug, but I added E2E test to make sure that my package won't suffer this bug in the future.

Really appreciate the fix!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants