【发布时间】: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