Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 节点js错误:spawn enoint_Javascript_Node.js_Svg - Fatal编程技术网

Javascript 节点js错误:spawn enoint

Javascript 节点js错误:spawn enoint,javascript,node.js,svg,Javascript,Node.js,Svg,我正在尝试使用节点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'] || "

我正在尝试使用节点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);
在执行时,我得到了这个错误(在MAC中)


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

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

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

我收到了错误信息

Uncaught Error: spawn myExeCommand ENOENT
一旦我将“选项”添加到spawn()中,它就起作用了

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

德普。我没有安装imagemagick。并使用猫鼬缩略图。谢谢有关其他信息,请参见。只需将
spawn
替换为
exec
即可修复我的所有问题(具有权限的路径中的linux二进制文件将不会执行)。是否有方法指定依赖项,以便npm install通知so安装包?
let options = {shell: true};
let theProcess = child_process.spawn(myExeCommand, null, options);