如何调试“错误:产生ENOENT”在node.js上? [英] How do I debug "Error: spawn ENOENT" on node.js?

查看:1211
本文介绍了如何调试“错误:产生ENOENT”在node.js上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

相关问题

  • using spawn function with NODE_ENV=production
  • node.js child_process.spawn ENOENT error - only under supervisord
  • spawn ENOENT node.js error
  • http://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
  • http://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)

推荐答案

简单的方法来获得根本原因的想法:

I found a particular easy way to get the idea of the root cause of:

Error: spawn ENOENT

此错误的问题是,错误消息中真的没有什么信息告诉您呼叫站点在哪里,即哪个可执行/命令是没有找到,特别是当你有一个很大的代码库,有很多的产生调用。另一方面,如果我们知道导致错误的确切命令,那么我们可以按照 @laconbass'answer 来修复

The problem of this error is, there is really little information in the error message to tell you where the call site is, i.e. which executable/command is not found, especially when you have a large code base where there are a lot of spawn calls. On the other hand, if we know the exact command that cause the error then we can follow @laconbass' answer to fix the problem.

我发现一个非常简单的方法来确定哪个命令导致问题,而不是在你的代码中添加事件侦听器,如@laconbass的答案中所建议的那样。最重要的想法是使用一个包装器打包原始的spawn调用,该包装器将发送的参数打印到spawn调用。

I found a very easy way to spot which command cause the problem rather than adding event listeners everywhere in your code as suggested in @laconbass' answer. The key idea is to wrap the original spawn call with a wrapper which prints the arguments send to the spawn call.

这是包装函数,放在 index.js 或您的服务器的起始脚本。

Here is the wrapper function, put it at the top of the index.js or whatever your server's starting script.

(function() {
    var childProcess = require("child_process");
    var oldSpawn = childProcess.spawn;
    function mySpawn() {
        console.log('spawn called');
        console.log(arguments);
        var result = oldSpawn.apply(this, arguments);
        return result;
    }
    childProcess.spawn = mySpawn;
})();

然后下次运行应用程序时,在未捕获的异常消息之前,您将看到如下信息:

Then the next time you run your application, before the uncaught exception's message you will see something like that:

spawn called
{ '0': 'hg',
  '1': [],
  '2':
   { cwd: '/* omitted */',
     env: { IP: '0.0.0.0' },
     args: [] } }

以这种方式你可以很容易地知道执行哪个命令,然后你可以找出为什么nodejs找不到可执行文件来解决问题。

In this way you can easily know which command actually is executed and then you can find out why nodejs cannot find the executable to fix the problem.

这篇关于如何调试“错误:产生ENOENT”在node.js上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆