heic2any icon indicating copy to clipboard operation
heic2any copied to clipboard

Reference error: Blob is not defined

Open daniel548604106 opened this issue 3 years ago • 3 comments

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 . image

I have no idea how to fix this and can't find related resources online .

Really appreciate if someone could help!

Thanks

daniel548604106 avatar Nov 10 '21 05:11 daniel548604106

I saw this error when I didn't select a file when the file dialog opened

tjdavenport avatar Nov 21 '21 18:11 tjdavenport

I have the same error just when I import the package (not even calling it)

Tonio-lavanda avatar Jul 28 '22 10:07 Tonio-lavanda

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",
          });
        }

Tonio-lavanda avatar Jul 28 '22 10:07 Tonio-lavanda

The library requires a full browser environment with DOM api to work

alexcorvi avatar Mar 29 '23 09:03 alexcorvi