javascript - Node js错误: spawn ENOENT

标签 javascript node.js svg

我正在尝试使用 node 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 中)

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)

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

最佳答案

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

关于javascript - Node js错误: spawn ENOENT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18846918/

相关文章:

javascript - 在 Node-webkit 中将 Canvas 保存到磁盘

node.js - Webstorm Nodejs 约定空间

javascript - 如何在函数外调用这个函数呢?

javascript - 使用 javascript/jquery 检查 .css 样式表的名称

javascript - 根据对象属性删除数组元素

html - 内联 SVG 不缩放

javascript - 调整多边形保持位置 - jQuery

javascript - 从 Axios React 排序数组

javascript - Node.js [网络库] : How to make the buffer object a string?

javascript - 添加到 Jekyll 社交分享按钮