当我得到以下错误:

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)

我该采取什么程序来修理呢?

作者注:这个错误的许多问题鼓励我发布这个问题,以供将来参考。

相关问题:

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)


当前回答

我在windows 8上得到了同样的错误。问题是由于系统路径的环境变量丢失。将“C:\Windows\System32\”值添加到系统PATH变量中。

其他回答

虽然对某些人来说这可能是一个环境路径或其他问题,但我刚刚在Windows 10上为Visual Studio Code安装了Latex Workshop扩展,并在尝试构建/预览PDF时看到了这个错误。作为管理员运行VS Code为我解决了这个问题。

我的解决方案

var spawn = require('child_process').spawn;

const isWindows = /^win/.test(process.platform); 

spawn(isWindows ? 'twitter-proxy.cmd' : 'twitter-proxy');
spawn(isWindows ? 'http-server.cmd' : 'http-server');

Windows解决方案:用节点交叉生成替换生成。例如,在你的app.js的开头:

(function() {
    var childProcess = require("child_process");
    childProcess.spawn = require('cross-spawn');
})(); 

我在windows 8上得到了同样的错误。问题是由于系统路径的环境变量丢失。将“C:\Windows\System32\”值添加到系统PATH变量中。

我也遇到了同样的问题,但我找到了一个简单的解决方法。 如果程序已经被用户添加到PATH(例如,正常的系统命令工作),它似乎是spawn()错误。

要解决这个问题,你可以使用which模块(npm install——save which):

// Require which and child_process
const which = require('which');
const spawn = require('child_process').spawn;
// Find npm in PATH
const npm = which.sync('npm');
// Execute
const noErrorSpawn = spawn(npm, ['install']);