0

当我运行这个我得到一个错误

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' }

我有这样的节点快速路由设置:

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

我不确定如何解决此错误。我在网上查找了食谱幻影-pdf 没有找到。

4

1 回答 1

4

这在最新的 0.2.3 版本中已修复,只需执行此操作即可npm install jsreport

一些提示:

您应该打开记录器来调查这些问题:

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

如果没有理由,您不应该为每个请求引导 jsreport。您可以考虑使用为您缓存单个实例的渲染快捷方式:

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

文档在这里

于 2014-12-11T21:24:39.383 回答