alexcorvi / heic2any

Converting HEIF/HEIF image formats to PNG/GIF/JPEG in the browser
https://alexcorvi.github.io/heic2any/
MIT License
626 stars 82 forks source link

Reference error: Blob is not defined #28

Closed daniel548604106 closed 1 year ago

daniel548604106 commented 2 years ago

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

tjdavenport commented 2 years ago

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

Tonio-lavanda commented 2 years ago

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

Tonio-lavanda commented 2 years ago

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",
          });
        }
alexcorvi commented 1 year ago

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