在使用npm安装pdfmake之后:
npm install pdfmake --save-dev在使用webpack编译包时,我在运行时得到一个错误:
pdfmake = require 'pdfmake'
pdfmake.createPdf(doc_definition).download('test.pdf')说:
pdfmake.createPdf is not a function我阅读了这建议,安装了脚本加载程序,并将需求更改为:
pdfmake = require 'script!pdfmake'但这导致了更多的错误。另外,我不知道需要什么脚本加载器。有什么建议吗?
编辑,如所描述的这里,似乎NPM安装了pdfmake的节点(服务器端)版本,而不是浏览器端版本,两者的API完全不同。这应该是浏览器端的正确流程:
npm install pdfmake --save-dev
pdfmake = require 'pdfmake'
pdfmake.createPdf(doc_definition).download('test.pdf')发布于 2020-03-18 15:11:33
在服务器端不支持createPdf方法。
服务器端pdfmake TypeError: pdfmake.createPdf不是一个函数#1355
但是我尝试了var PDF = require('pdfmake/build/pdfmake'),错误就消失了。
另外,我建议你也买vfs_fonts
var PDF_Fonts=require('pdfmake/build/vfs_fonts')
然后像这样设置pdfmake.vfs
PDF.vfs = PDF_Fonts.pdfMake.vfs;
https://stackoverflow.com/questions/35494376
复制相似问题