heic2any
heic2any copied to clipboard
Reference error: Blob is not defined
Hi , I'm trying to implement heic2any in my project , but the very first thing that blocks me from moving on is the error in my log that shows Reference error : Blob is not defined .
I have no idea how to fix this and can't find related resources online .
Really appreciate if someone could help!
Thanks
I saw this error when I didn't select a file when the file dialog opened
I have the same error just when I import the package (not even calling it)
my problem is that I was using this library inside a Next project.
During Server side rendering, Blob is not defined.
The solution was to dinamycally import the library when needed (more info on this on the nextjs documentation)
So my code look like
if (file.type === "image/heic") {
const heic2any = (await import("heic2any")).default;
const newFile = await heic2any({
blob: file,
toType: "image/jpeg",
});
}
The library requires a full browser environment with DOM api to work