html2pdf.js
html2pdf.js copied to clipboard
Does this work with Vite?
Just trying to get this library working in a vue 3 project which uses Vite and not webpack.
Just passing in a simple html div into html2Pdf and see following error:
TypeError: html2canvas__WEBPACK_IMPORTED_MODULE_9__ is not a function at Promise2.toCanvas_main (http://localhost:8081/node_modules/.vite/html2pdf_js.js?v=95ddde7e:9804:24) at invokeCallback (http://localhost:8081/node_modules/.vite/html2pdf_js.js?v=95ddde7e:12490:29) at publish (http://localhost:8081/node_modules/.vite/html2pdf_js.js?v=95ddde7e:12479:21) at MutationObserver.flush (http://localhost:8081/node_modules/.vite/html2pdf_js.js?v=95ddde7e:12293:19)
Anyone got this package working with Vite?
I have the same problem
貌似是html2canvas的版本问题,尝试修改src/worker.js 第二行
import * as html2canvas from 'html2canvas';
改成
import html2canvas from 'html2canvas';
重新编译生成
having the same problem, did you guys solved it?
Hey, @alttabs @icefee @jordcodes
I have a solution.
Add below code to index.html
:
<script
src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"
integrity="sha512-GsLlZN/3F2ErC5ifS5QtgpiJtWd43JWSuIgh7mbzZ8zBps+dvLusV+eNQATqgA/HdeKFVgA5v3S/cIrLF7QnIg=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
you need to suppress typescript error for the library with @ts-ignore
like below:
// @ts-ignore
html2pdf()
you don't need import anything, html2pdf
is global now
@ridvanaltun So we can't use the npm version?