Search code examples
node.jsasp.net-corejsrenderjsreportjavascriptservices

AspNetCore NodeServices throws NodeInvocationException


I am using NodeServices to create PDF in AspNetCore app. App works fine on local machine but when deployed on production, on calling the pdf function, I get the following error:

Error: spawn D:\home\site\wwwroot\node_modules\phantomjs\lib\phantom\bin\phantomjs ENOENT at _errnoException (util.js:1022:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19) at onErrorNT (internal/child_process.js:372:16) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)

Microsoft.AspNetCore.NodeServices.HostingModels.NodeInvocationException: Error during rendering report: spawn D:\home\site\wwwroot\node_modules\phantomjs\lib\phantom\bin\phantomjs ENOENT

Error: spawn D:\home\site\wwwroot\node_modules\phantomjs\lib\phantom\bin\phantomjs ENOENT at _errnoException (util.js:1022:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19) at onErrorNT (internal/child_process.js:372:16) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9)

I verified that all the files are at their right place. node_modules are present in the deployment.

Node Version on Azure: 8.9.4

Code to generate PDF:

module.exports = function (callback, html) {
var jsreport = require('jsreport-core')();

jsreport.init().then(function () {
    return jsreport.render({
        template: {
            content: html,
            engine: 'jsrender',
            recipe: 'phantom-pdf'
        }
    }).then(function (resp) {
        callback(/* error */ null, resp.content.toJSON().data);
    }).catch(function (e) {
        callback(/* error */ e, null);
    });
}).catch(function (e) {
    callback(/* error */ e, null);
});
};

Solution

  • The issue was with the installation of Node packages. I was using Hosted Linux on Azure to build the solution. Switched to Hosted VS2017 build and everything is working smoothly. https://github.com/pofider/phantom-html-to-pdf/issues/68