产卵事件错误- NodeJS

Spawn ENOENT error - NodeJS

本文关键字:NodeJS 错误 事件      更新时间:2023-09-26

我正在尝试使用InDesign Server使用变量通过表单传递到InDesign脚本中创建服务订单。

但是我一直得到以下错误:

/Users/rickybarnett/Desktop/curries-indesign/oos-w2p.dev/oos-curries/routes/oos.js:422
    if(err) throw err;
^Error: spawn ENOENT
  at errnoException (child_process.js:988:11)
  at Process.ChildProcess._handle.onexit (child_process.js:779:34)
  21 May 20:27:57 - [nodemon] app crashed - waiting for file changes before starting...

我已经安装了所有依赖项,并使用npm-install-missing模块进行了检查。

这个错误只发生在我的一个路由上:

// ROUTES FOR FIRST PAGE **************************************************************************************
/* GET load the first page for user editing */
router.get('/first-page', function(req, res) {
// get the pages json input list
var json = req.session.template.page_one_setup;
var form = JSON.parse(json);
TrimColours.getDropdownItems(function(results) {
    res.render('oos/first-page', {trimColours: results, form: form, templateColor: req.session.templateColor});
});
});
router.post('/first-page-indesign', function(req, res){
// get the templates json input list
var json = req.session.template.page_one_setup;
var form = JSON.parse(json);
var body = req.body;
var trimColourId = body.trim_colour_id;
//perform validation
req.checkBody('name', 'Please provide a name').notEmpty();
req.checkBody('trim_colour_id', 'Please select the trim colour').notEmpty();
var errors = req.validationErrors();
if(errors) {
    res.send({errors: errors});
    return;
}
TrimColours.getTrimColourValueById(trimColourId, function(result) {
    //store the value of trim colour in session
    req.session.trimColour = result.colour_value;
    req.session.templateColor = body.colorpicker;
    // prepare the base arguments required by the script
    var args = [
        {name: 'applicationPath', value: settings.PROJECT_DIR },
        {name: 'colour', value: req.session.colourValue},
        {name: 'trimColour', value: result.colour_value},
        {name: 'templateName', value: req.session.template_file},
        {name: 'pageNumber', value: "1" },
        {name: 'pageColor', value: body.colorpicker},
    ];
    var inputs = "";
    // loop over the form json string to set up the args array to be sent to the indesign script
    // and to create the inputs array to be passed into the the script so the script can resolve the
    // arguments and assign them to correct page items
    for (var i = 0; i < form.length; i++) {
        args.push({name: form[i].input_name, value: body[form[i].input_name] });
        inputs += form[i].input_name + ",";
    };
    args.push({name: 'inputs', value: inputs.substring(0, inputs.length - 1)});
    //Call the indesign server
    runScript(args, body, function(result) {
        req.session.userFile = result.fileName
        //get unique image path returned from indesign script
        var imagePath =  "/oos-preview-image/" + result.image;
        res.send(imagePath);
    });
});
});

第442行包含在这里:"if(err) throw err;"

//function responsible for cropping an image and sending back the path
router.get('/crop-image', function(req, res) {
var url_parts = url.parse(req.url, true);
var query = url_parts.query;
var coords = query.coords.split(',');
//split the image name by "."
var croppedImageName = query.image.split('.')[0];
var extensionName = Math.round(new Date().getTime() / 1000);
//loop over the coordinates and change them into an int
for (var i = 0; i < coords.length; i++) {
    coords[i] = +coords[i];
};
//create a new cropped image and pass back the name
gm(settings.PROJECT_DIR +'/public/user-images/' + query.image)
.crop(coords[0], coords[1], coords[2], coords[3])
.write(settings.PROJECT_DIR +'/public/user-images/' + croppedImageName + "_croped_" + extensionName + ".png", function(err){
    if(err) throw err;
    res.send(croppedImageName + "_croped_"+ extensionName +".png");
});
});

您是否在使用ImageMagick ?

  • 如果是,是否安装在您的计算机上?(从这里安装:链接)

  • 如果没有,你应该这样使用:


var gm = require("gm");
var im = gm.subClass({imageMagick: true});
im("path/image.png")
    .crop(10,10,10,10)
    .write("path/imagecropped.png", function(err){
        if(err){throw err;}
    });

由于某些原因,npm没有正确安装graphicsmagick,通过安装home-brew然后通过它安装graphicsmagick来修复这个问题。