4

after executing a command with execSync which executes with sh I noticed the following:

spawnSync /bin/sh ENOENT

bin is currently added to PATH.

any thoughts?

Drew
  • 2,583
  • 5
  • 36
  • 54

2 Answers2

8

Normally the cause is that the path where you are executing this doesn't exist

see the accepted answer in this question

How do I debug “Error: spawn ENOENT” on node.js?

Community
  • 1
  • 1
stalin
  • 3,442
  • 2
  • 25
  • 25
  • hmm...so if I execute `/bin/sh` in console it does find the folder – Drew Sep 28 '16 at 17:56
  • 2
    is not that the /bin/sh is not there is that the folder where are you running the command not exist like if you do: exec('pwd', { cwd:'/home/user/directory'}; will fail with the error if the cwd path not exist – stalin Sep 28 '16 at 17:58
  • hmm would it not error out saying the cwd does exist as opposed to bin/sh? – Drew Sep 28 '16 at 18:05
  • this is the problem, node not say that the cwd not exists just say that [Error: spawn /bin/sh ENOENT] – stalin Sep 28 '16 at 18:48
7

This error can also be caused by passing a directory that does not exist to the cwd. Double check that the path you are passing as the cwd option is correct.

Code Commander
  • 16,771
  • 8
  • 64
  • 65
  • wow! that was exactly my case! I spent a lot of time trying to figure out what was the issue, but didn't event think that I made a typo in cwd parameter for PM2 ecosystem file. Thanks! – Dmytro Dec 05 '20 at 21:11