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

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

问题描述

当我收到以下错误时:

events.js:72扔er;//未处理的错误"事件^错误:生成 ENOENT在 errnoException (child_process.js:1000:11)在 Process.ChildProcess._handle.onexit (child_process.js:791:34)

我可以按照什么程序来修复它?

作者注:此错误的许多问题促使我发布此问题以供将来参考.

相关问题:

解决方案

如何研究引发错误的 spawn 调用:

已知的常见原因

  1. 环境问题

    • 系统中不存在该命令可执行文件(未安装依赖项).参见prominc 的回答
    • PATH 环境变量指定的目录中不存在命令可执行文件.
  2. 仅限 Windows 的错误/怪癖

  3. 错误的spawn('command', ['--argument', 'list'], { cwd, env, ...opts }) 用法

    • 指定的工作目录 (opts.cwd) 不存在·参见 leeroy-brun 的回答
    • 命令中的参数列表String spawn('command --wrong --argument list')
    • 命令字符串中的环境变量 spawn('ENV_VAR=WRONG command')
    • 参数列表 Array 指定为 String spawn('cmd', '--argument list')
    • 取消设置 PATH env 变量 spawn('cmd', [], { env: { variable } } => spawn('cmd', [], { env: { ...process.env, variable } }


<块引用>

ENOENT 有 2 个可能的起源:

  1. 您正在编写的代码
  2. 你依赖的代码

当来源是您所依赖的代码时,通常的原因是环境问题(或 Windows 怪癖)


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:

解决方案

How to research the spawn call raising the error:

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.
  2. Windows-only bugs/quirks

  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)


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

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