node.jsdebuggingerror-handlingchild-processspawn

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


When I get the following error:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:1000:11)
    at Process.ChildProcess._handle.onexit (child_process.js:791:34)

What procedure can I follow to fix it?

Author note: Lots of issues with this error encouraged me to post this question for future references.

Related questions:


Solution

  • How to research the spawn call raising the error:

    Known, usual causes

    1. Environment issues

      • The command executable does not exist within the system (dependency not being installed). see prominc's answer
      • The command executable does not exist within a directory of those specified by PATH environment variable.
      • The executable binary was compiled with uncompatible libraries. see danilo-ramirez answer
    2. Windows-only bugs/quirks

    3. Wrong spawn('command', ['--argument', 'list'], { cwd, env, ...opts }) usage

      • Specified working directory (opts.cwd) does not exist · see leeroy-brun's answer
      • Argument list within command String spawn('command --wrong --argument list')
      • Env vars within command string spawn('ENV_VAR=WRONG command')
      • Argument list Array specified as String spawn('cmd', '--argument list')
      • Unset PATH env variable spawn('cmd', [], { env: { variable } } => spawn('cmd', [], { env: { ...process.env, variable } }

    There are 2 posible origins for ENOENT:

    1. Code you are writing
    2. Code you depend on

    When origin is code you depend on, usual cause is an Environment Issue (or windows quirk)