【问题标题】:node-jspdf pdf generation node.jsnode-jspdf pdf生成 node.js
【发布时间】:2016-05-23 20:53:06
【问题描述】:

我实际上是在尝试在 node.js 应用程序中包含 node-jspdf。

执行的步骤

  • npm install node-jspdf --save
  • cd node_modules/node-jspdf/
  • npm 安装

ge-pdf.js 内容

var jspdf = require('node-jspdf');

执行文件 节点ge-pdf.js

抛出以下错误

Error: Cannot find module './vendor/jsPDF/jspdf.plugin.addhtml.js'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)

更新了 node_modules/node-jspdf/index.js 文件

plugins.map(function(plugin){
    require(path+'jspdf.plugin.'+plugin+'.js');
});

plugins.map(function(plugin){
    require(path+'plugins/'+plugin+'.js');
});

在此更改之后,当我执行文件时。 节点ge-pdf.js

抛出以下错误

node_modules/node-jspdf/vendor/jsPDF/plugins/addhtml.js:116
})(jsPDF.API);
        ^
TypeError: Cannot read property 'API' of undefined
    at Object.<anonymous> (/home/antho/node_pdf/node_modules/node-jspdf/vendor/jsPDF/plugins/addhtml.js:116:9)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at /home/antho/node_pdf/node_modules/node-jspdf/index.js:7:5

【问题讨论】:

  • 我注意到你写了var jspdf = require('node-jspdf');,但你在底部使用的变量是`jsPDF'。可能只是大写/小写语法错误。
  • 大小写正确。查看 package.json 文件后,模块名称也正确。 github.com/calvinfroedge/node-jspdf/tree/master。第一行 require('node-jspdf') 抛出错误。
  • 请注意,您可以通过一些小技巧直接将 jspdf 与 node 一起使用。见stackoverflow.com/a/41898470/827047

标签: javascript node.js pdf jspdf


【解决方案1】:

这在 node-jspdf 的 Github 上被记录为 issue

Node-jspdf 引入了 jspdf 的“主”版本。的版本 当前在 npm 存储库(0.0.3)中的 node-jspdf 不是 兼容jspdf母版。

如果您执行 'npm install https://github.com/calvinfroedge/node-jspdf.git',这会给你一个 与主版本兼容的 node-jspdf 的较新副本 jspdf。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2018-05-19
    • 2021-10-31
    • 1970-01-01
    • 2019-08-28
    • 2017-09-02
    相关资源
    最近更新 更多