我如何调试“错误:生成 ENOENT"?在 node.js 上? [英] How do I debug "Error: spawn ENOENT" on node.js?
本文介绍了我如何调试“错误:生成 ENOENT"?在 node.js 上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我收到以下错误时:
events.js:72扔er;//未处理的错误"事件^错误:生成 ENOENT在 errnoException (child_process.js:1000:11)在 Process.ChildProcess._handle.onexit (child_process.js:791:34)
我可以按照什么程序来修复它?
作者注:此错误的许多问题促使我发布此问题以供将来参考.
相关问题:
- 在 NODE_ENV=production 中使用 spawn 函数
- node.js child_process.spawn ENOENT 错误 -仅在监督下
- 产生 ENOENT node.js 错误
- https://stackoverflow.com/questions/27603713/nodejs-spawn-enoent-error-on-travis-calling-global-npm-package
- Node JS -Grunt 任务中的 child_process spawn('npm install') 导致 ENOENT 错误
- 运行工头"任务致命错误:生成 ENOENT
- 节点 js 中未处理的错误事件错误:在 errnoException (child_process.js:975:11) 处生成 ENOENT
- Node.js SpookyJS:执行 hello.js 时出错
- https://stackoverflow.com/questions/26572214/run-grunt-on-a-directory-nodewebkit
- 使用子进程 NodeJS 运行 exe 文件
- 节点:child_process.spawn 即使在路径中(ENOENT)也不能在 Java 上工作
- 使用 NodeJS 产生 ENOENT 错误(PYTHON 相关)
- 图像大小调整在 node.js 中不起作用(partial.js)(未安装的依赖)
- npm 安装错误 ENOENT(构建依赖问题)
- 无法在 Windows 7 上安装 node.js - oracle 模块(构建依赖问题)
- 在 windows 上使用 nodejs 安装 gulp 时出错(奇怪的情况)
解决方案
如何研究引发错误的 spawn 调用:
- 使用 NODE_DEBUG=child_process,感谢@karl-richter.简单、快速,2019 年 10 月
- 使用包装器装饰
child_process.spawn
,感谢@jiaji-zhou.简单、快速,2015 年 1 月 - 漫长的过程,感谢@laconbass.复杂,时间成本,2014 年 12 月
已知的常见原因
环境问题
- 系统中不存在该命令可执行文件(未安装依赖项).参见prominc 的回答
PATH
环境变量指定的目录中不存在命令可执行文件.
仅限 Windows 的错误/怪癖
错误的
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 个可能的起源:
- 您正在编写的代码
- 你依赖的代码
当来源是您所依赖的代码时,通常的原因是环境问题(或 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:
- using spawn function with NODE_ENV=production
- node.js child_process.spawn ENOENT error - only under supervisord
- spawn ENOENT node.js error
- https://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
- https://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)
解决方案
How to research the spawn call raising the error:
- Use NODE_DEBUG=child_process, Credits to @karl-richter. Simple, quick, October 2019
- Use a wrapper to decorate
child_process.spawn
, Credits to @jiaji-zhou. Simple, quick, January 2015 - Long procedure, credits to @laconbass. Complex, time-cost, December 2014
Known, usual causes
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.
Windows-only bugs/quirks
- '.cmd' extension / shell: true. see li-zheng answer
- Administrator permisions. see steve's answer
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 asString
spawn('cmd', '--argument list')
- Unset
PATH
env variable=>spawn('cmd', [], { env: { variable } }
spawn('cmd', [], { env: { ...process.env, variable } }
- Specified working directory (
There are 2 posible origins for
ENOENT
:
- Code you are writing
- Code you depend on
When origin is code you depend on, usual cause is an Environment Issue (or windows quirk)
这篇关于我如何调试“错误:生成 ENOENT"?在 node.js 上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文