【问题标题】:Getting Error: spawn ./node_modules/.bin/grunt ENOENT when running grunt出现错误:运行 grunt 时产生 ./node_modules/.bin/grunt ENOENT
【发布时间】:2017-05-02 12:13:16
【问题描述】:

我有一个项目正在开发中

yarn start

它运行一个 index.js 启动一个 grunt 进程并得到这个错误:

$ 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.

不知道会是什么。环境是:

  • Win10
  • 使用 MINGW64 运行

【问题讨论】:

    标签: node.js windows gruntjs child-process


    【解决方案1】:

    我通常会打补丁child_process 来帮助我调试这类问题。在 index.js 文件的开头添加类似这样的内容:

    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);
    };
    

    如果你运行childProcess.spawn('ls', ['-lh', '/usr']),你会看到类似:

    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' ] }
    

    也许在运行它之后,您可以使用新信息更新您的问题。

    【讨论】:

    • 感谢@Danziger,我通过切换到 linux 解决了这个问题;)
    猜你喜欢
    • 2017-10-23
    • 1970-01-01
    • 2020-04-22
    • 2014-06-23
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    相关资源
    最近更新 更多