简体   繁体   中英

Spawn ENOENT error - NodeJS

I'm trying to create a order of service using InDesign Server using variables passed through a form into the InDesign Script.

But I keep getting the following error:

/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...

I have all dependancies installed and have checked using the npm-install-missing module also.

This error only occurs on one of my routes:

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

Line 442 is contained here: "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");
});

});

Are you using ImageMagick ?

  • If yes, is it installed on your computer ? (install from here : Link )

  • If no, you should use it like this :


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 来解决这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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