R01010010
R01010010

Reputation: 5958

Getting Error: spawn ./node_modules/.bin/grunt ENOENT when running grunt

I have a project that is started in development by

yarn start

It runs a index.js that starts a grunt process and get this error:

$ yarn start
yarn start v0.23.2
$ node ./development
grunt_arguments [ '--force', '--notify', '--verbose', '--debug', '--stack' ]
=======================================
Open http://localhost:8000 to start developing

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: spawn ./node_modules/.bin/grunt ENOENT
    at exports._errnoException (util.js:907:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:189:32)
    at onErrorNT (internal/child_process.js:355:16)
    at nextTickCallbackWith2Args (node.js:458:9)
    at process._tickCallback (node.js:372:17)
    at Function.Module.runMain (module.js:443:11)
    at startup (node.js:139:18)
    at node.js:990:3
error Command failed with exit code 1.

No idea what can it be. Environment is:

Upvotes: 0

Views: 457

Answers (1)

Danziger
Danziger

Reputation: 21161

I usually monkey patch child_process to help me debug that kind of issues. Add something like this in the beginning of your index.js file:

const util = require('util')
const childProcess = require("child_process");

const originalSpawn = childProcess.spawn;

childProcess.spawn = function() {
    console.trace('SPAWN');
    console.log('ARGS');
    console.log(util.inspect(arguments, false, null)); // showHidden = false, depth = null

    return originalSpawn.apply(this, arguments);
};

If your run, childProcess.spawn('ls', ['-lh', '/usr']) you will see something like:

Trace: SPAWN
    at Object.childProcess.spawn (repl:2:9)
    at myFunction (repl:2:14)
    at repl:1:1
    at REPLServer.defaultEval (repl.js:164:27)
    at bound (domain.js:250:14)
    at REPLServer.runBound [as eval] (domain.js:263:12)
    at REPLServer.<anonymous> (repl.js:392:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:210:10)
ARGS
{ '0': 'ls', '1': [ '-lh', '/usr' ] }

Maybe after running it you can update your question with the new information.

Upvotes: 2

Related Questions