PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, November 14, 2022

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

 November 14, 2022     child-process, debugging, error-handling, node.js, spawn     No comments   

Issue

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:

  • using spawn function with NODE_ENV=production
  • node.js child_process.spawn ENOENT error - only under supervisord
  • spawn ENOENT node.js error
  • https://stackoverflow.com/questions/27603713/nodejs-spawn-enoent-error-on-travis-calling-global-npm-package
  • Node JS - child_process spawn('npm install') in Grunt task results in ENOENT error
  • Running "foreman" task Fatal error: spawn ENOENT
  • unhandled error event in node js Error: spawn ENOENT at errnoException (child_process.js:975:11)
  • Node.js SpookyJS: error executing hello.js
  • https://stackoverflow.com/questions/26572214/run-grunt-on-a-directory-nodewebkit
  • Run exe file with Child Process NodeJS
  • Node: child_process.spawn not working on Java even though it's in the path (ENOENT)
  • spawn ENOENT error with NodeJS (PYTHON related)
  • image resizing is not working in node.js (partial.js) (non-installed dependency)
  • npm install error ENOENT (build dependency problem)
  • Cannot install node.js - oracle module on Windows 7 (build dependency problem)
  • Error installing gulp using nodejs on windows (strange case)

Solution

How to research the spawn call raising the error:

  • Use NODE_DEBUG=child_process, Credits to @karl-richter. Simple, quick, October 2019
  • Use a wrapper to decorate child_process.spawn, Credits to @jiaji-zhou. Simple, quick, January 2015
  • Long procedure, credits to @laconbass. Complex, time-cost, December 2014

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

    • '.cmd' extension / shell: true. see li-zheng answer
    • Administrator permisions. see steve's answer
  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)




Answered By - laconbass
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing