Node.Js npm PDFKit在调用doc.end()

时间:2018-03-16 16:17:10

标签: node.js module crash pdfkit

的Helloworld!

今天,我从模块pdfkit收到了一个奇怪的错误:

TypeError: font.finalize is not a function
at PDFDocument.end (C:\Users\James\Desktop\c4t\server\node_modules\pdfkit\js\document.js:202:14)
at app.get (C:\Users\James\Desktop\c4t\server\routes\pdf.js:8:13)
at Layer.handle [as handle_request] (C:\Users\James\Desktop\c4t\server\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\James\Desktop\c4t\server\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\James\Desktop\c4t\server\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\James\Desktop\c4t\server\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\James\Desktop\c4t\server\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\James\Desktop\c4t\server\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\James\Desktop\c4t\server\node_modules\express\lib\router\index.js:275:10)
at module.exports (C:\Users\James\Desktop\c4t\server\tools\i18n.js:16:5)

我尝试重新安装pdfkit并以简单的路径封装pdfkit:

var PDFDocument = require("pdfkit");
app.get("/test2", (req, res) => {
    var doc = new PDFDocument();
    doc.end();
});

每当应用程序崩溃时,总是在调用doc.end();

时崩溃

你有什么建议为什么它一直在崩溃? 谢谢!

JamesDeschê​​nes

1 个答案:

答案 0 :(得分:0)

最后,我发现了。 我扩展了像Object.prototype.foo = function(){}这样的对象专有权。 (这不是一个好主意。)

由于我不知道的原因,pdfKit不喜欢和崩溃。 所以我装饰了我需要我的foo原型的特定对象,一切都还可以。