I get Error Phantom-pdf recipe was not found and then another error when using jsreport node module

淺唱寂寞╮ 提交于 2019-12-12 01:55:20

问题


When I run this I get an error

GET /pdfreport - - ms - -
WARRNING! '$data.ObjectID' not supported as computed Key!
WARRNING! '$data.ObjectID' not supported as computed Key!
WARRNING! '$data.ObjectID' not supported as computed Key!
WARRNING! '$data.ObjectID' not supported as computed Key!
WARRNING! '$data.ObjectID' not supported as computed Key!
Recipe phantom-pdf was not found.
GET /pdfreport - - ms - -
{ [Error: ENOENT, unlink '/var/folders/r0/l6_3z9g55x95s7dp34yt3scw0000gn/T/xcrun_db']
  errno: 34,
  code: 'ENOENT',
  path: '/var/folders/r0/l6_3z9g55x95s7dp34yt3scw0000gn/T/xcrun_db' }

I have my node express route setup like this:

app.route('/pdfreport')
    .get(function (req, res) {

        var jsreport = require('jsreport');
        jsreport.bootstrapper(jsreport.renderDefaults).start().then(function(conf) {
                conf.reporter.render({
                    template: {
                        content: "<h1>Hello world</h1>",
                        phantom: {
                            header: "<p>some header</p>",
                            orientation: "portrait",
                            width: "300px"
                        }
                    }
                }).then(function(out) {
                    out.result.pipe(res);
                }).fail(function(e) {
                    console.log(e);
                });
        });
    });

I am not sure how to resolve this error. I have looked online for the Recipe phantom-pdf was not found.


回答1:


This is fixed in the latest 0.2.3 version, just do npm install jsreport and it should work.

Some hints:

You should turn on logger to investigate these issues:

jsreport.renderDefaults.logger.providerName = "console";

You should not bootstrap jsreport for every request if there is no reason for it. You can maybe consider using a render shortcut which cache single instance for you:

app.route('/pdfreport')
    .get(function (req, res) {
        require('jsreport').render({
                    template: {
                        content: "<h1>Hello world</h1>",
                        phantom: {
                            header: "<p>some header</p>",
                            orientation: "portrait",
                            width: "300px"
                        }
                    }
                }).then(function(out) {
                    out.result.pipe(res);
                }).fail(function(e) {
                    console.log(e);
                });
  });

Documentation is here



来源:https://stackoverflow.com/questions/27427684/i-get-error-phantom-pdf-recipe-was-not-found-and-then-another-error-when-using-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!