简体   繁体   English

节点js错误:生成ENOENT

[英]Node js Error: spawn ENOENT

I am trying to convert SVG to PNG with node js. 我试图用节点js将SVG转换为PNG。 My code is here: 我的代码在这里:

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. 我已经为nodejs指定了路径。 But i dont know why it fails. 但我不知道它失败的原因。 Any idea about this issue? 对这个问题有什么看法吗?

It's likely failing because it can't find the convert application. 它可能会失败,因为它无法找到convert应用程序。 Does the path to convert exist in your environment PATH? convert路径是否存在于您的环境PATH中? Can you run convert from your terminal? 你可以从终端运行convert吗?

I had this same issue running from Linux. 我从Linux运行同样的问题。 I did the npm install unoconv and 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 我做了npm install unoconv并认为这将负责安装转换应用程序,但只有当我安装它时才能让它在Node.js中运行sudo apt-get install unoconv

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM