node.js - AspNetCore NodeServices 抛出 NodeInitationException

标签 node.js asp.net-core jsrender jsreport javascriptservices

我正在使用 NodeServices 在 AspNetCore 应用程序中创建 PDF。应用程序在本地计算机上运行良好,但在生产中部署时,在调用 pdf 函数时,出现以下错误:

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)

我确认所有文件都位于正确的位置。 node_modules 存在于部署中。

Azure 上的 Node 版本:8.9.4

生成 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);
});
};

最佳答案

如果您通过免费计划使用 Azure 应用服务,则无法在服务器上呈现 pdf。这是因为该服务在沙箱中运行,因此无法运行第三方可执行文件,例如 node.exe。您需要将服务套餐升级到“基本”或更高版本。

关于node.js - AspNetCore NodeServices 抛出 NodeInitationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49561371/

相关文章:

javascript - 将变量传递到正在运行的 Node.js 程序中

javascript - 在 jsrender 中链接来自不同 json 对象的数据

jquery - 错误 : view. hlp(...) 不是 jsrender 中的函数

node.js - Nodejs 异步系列 - 将参数传递给下一个回调

javascript - Node.js Passport 身份验证忽略 Controller 功能

asp.net - UserManager - 访问已处置对象

docker - 无法创建docker镜像。找不到与global.json版本兼容的SDK版本:[/app/global.json]中的[2.2.106]

asp.net-core - ASP.Net Core 排除除英语以外的已发布语言目录

javascript - JSRender 条件语句

Node.js + Twitter 流内存泄漏