node.js 节点js错误:产生ENOENT

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18846918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:38:16  来源:igfitidea点击:

Node js Error: spawn ENOENT

javascriptnode.jssvg

提问by sprabhakaran

I am trying to convert SVG to PNG with node js. My code is here:

我正在尝试使用节点 js 将 SVG 转换为 PNG。我的代码在这里:

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'image/png'});
  var convert = child_proc.spawn("convert", ["svg:", "png:-"]),
      values = (url.parse(req.url, true).query['values'] || ".5,.5")
        .split(",")
        .map(function(v){return parseFloat(v)});

  convert.stdout.on('data', function (data) {
    res.write(data);
  });
  convert.on('exit', function(code) {
    res.end();
  });

  jsdom.env({features:{QuerySelector:true}, html:htmlStub, scripts:scripts, done:function(errors, window) {
    var svgsrc = window.insertPie("#pie", w, h, values).innerHTML;
    //jsdom's domToHTML will lowercase element names
    svgsrc = svgsrc.replace(/radialgradient/g,'radialGradient');
    convert.stdin.write(svgsrc);
    convert.stdin.end();
  }});
}).listen(8888);

While executing I got this error (in MAC)

执行时出现此错误(在 MAC 中)

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:980:11)
    at Process.ChildProcess._handle.onexit (child_process.js:771:34)

I have specified the path for nodejs. But i dont know why it fails. Any idea about this issue?

我已经指定了 nodejs 的路径。但我不知道为什么它失败了。对这个问题有什么想法吗?

回答by badsyntax

It's likely failing because it can't find the convertapplication. Does the path to convertexist in your environment PATH? Can you run convertfrom your terminal?

它可能会失败,因为它找不到convert应用程序。路径是否convert存在于您的环境 PATH 中?你可以convert从你的终端运行吗?

回答by Sagan

I was getting the error

我收到错误

Uncaught Error: spawn myExeCommand ENOENT

Once I added 'options' to the spawn(), it worked.

一旦我向 spawn() 添加了“选项”,它就起作用了。

let options = {shell: true};
let theProcess = child_process.spawn(myExeCommand, null, options);

回答by Lance

I had this same issue running from Linux. I did the npm install unoconvand thought that that would take care of installing the convert application, but only when I had installed it could I get it to run in Node.js sudo apt-get install unoconv

我在 Linux 上运行时遇到了同样的问题。我做了npm install unoconv并认为这将负责安装转换应用程序,但只有当我安装它时,我才能让它在 Node.js 中运行 sudo apt-get install unoconv