[Node.js] How to Fix Error: spawn ENOENT

Tadashi Shigeoka ·  Wed, September 16, 2015

I’ll introduce how to fix the Error: spawn ENOENT error that occurs in Node.js child_process.spawn.

Node.js | ノードジェイエス

To get straight to the point, the cause was that the command to execute didn’t exist in the path passed as the first argument to child_process.spawn.

In this case, it was the ImageMagick command.

Context

Code that caused the error (partial excerpt only)

imagemagick = require 'imagemagick'
child_process = require 'child_process'

spawned_child_process = child_process.spawn imagemagick.identify.path

Error Message

Error: spawn ENOENT
  at errnoException (child_process.js:988:11)
  at Process.ChildProcess._handle.onexit (child_process.js:779:34)

How to Fix Error: spawn ENOENT

I had installed the node-imagemagick npm module, but the essential ImageMagick itself wasn’t installed, which was the cause.

When I checked if ImageMagick was installed using the brew list command, it wasn’t there.

brew list | grep imagemagick

If it’s not installed, let’s install ImageMagick.

brew install xz # ImageMagick Dependencies
brew install imagemagick

This should prevent the Error: spawn ENOENT error from occurring and allow image uploads to work.

Reference Information

That’s all from the Gemba.