How to properly load html2pdf.js lib?
Answered
Belgian Hare posted this in #help-forum
Belgian HareOP
I just imported this lib and using it, it works but in the console i get this error. I tried dynamic import but that caused other issues before
whats the proper way to load this library
import html2pdf from "html2pdf.js";
const downloadPdf = async () => {
let content = document.getElementById("invoice");
html2pdf(content, {
filename: `${invoiceData.invoiceNo}.pdf`,
image: { type: "jpeg", quality: 1 },
html2canvas: { scale: 2 },
}).save();
};whats the proper way to load this library
Answered by Belgian Hare
i fixed the issue by importing the modal which has html2pdf by next- dynamic
22 Replies
You have internal server error, check your vscode terminal
The console is throwing an error for the
/login route, but your code has no mention of that route.@flap The console is throwing an error for the `/login` route, but your code has no mention of that route.
Belgian HareOP
cuz the invoice modal component i got is imported on common modules which runs in main layout
Belgian HareOP
i fixed the issue by importing the modal which has html2pdf by next- dynamic
Answer
Belgian HareOP
+ ssr false
I am 99% sure that it wasn't the root cause
@James4u I am 99% sure that it wasn't the root cause
Belgian HareOP
it was
show me the whole codebase of
InvoiceModal@Belgian Hare
@James4u show me the whole codebase of `InvoiceModal`
Belgian HareOP
that has the import of html2pdf
I know, show me the full codebase
when do you call
downloadPdf function?@James4u I know, show me the full codebase
Belgian HareOP
@James4u the full codebase not the function
Belgian HareOP
its a private repo
on btn click
although
next/dynamic with ssr: false fixed your issue but it wasn't due to downloadPdf() if it's called on button click@James4u although `next/dynamic` with `ssr: false` fixed your issue but it wasn't due to `downloadPdf()` if it's called on button click
Belgian HareOP
yes but it was due to the import of html2pdf
@Belgian Hare yes but it was due to the import of html2pdf
Nope, just importing a library can't cause the error