Spawn ENOENT错误 - NodeJS

时间:2014-05-21 19:36:11

标签: javascript jquery node.js express jsx

我正在尝试使用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");
});

});

2 个答案:

答案 0 :(得分:1)

您使用的是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;}
    });

答案 1 :(得分:0)

出于某种原因,npm没有正确安装graphicsmagick,通过安装home-brew然后通过安装graphicsmagick修复此问题。