alexcorvi / heic2any

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

Web workers #19

Closed KNazarenko closed 1 year ago

KNazarenko commented 3 years ago

Hi,

The description indicates that the library can be used asynchronously using web workers.

When importing a library into a web worker, I got an error: Uncaught ReferenceError: window is not defined.

Is there a solution?

Tim-mhn commented 2 years ago

Having the same issue. I don't see how it could work since the library uses the window object which doesn't exist in the scope in which the WebWorker is running according to the MDN Docs. Also confirmed by this stack overflow post

chebum commented 2 years ago

I believe the author meant the library uses web workers to process images.

barisbll commented 1 year ago

The error is caused by the lack of window object in our environment. I believe this happens because our code somehow looses this object inside the bundlers like webpack

My solution is mocking the window object

jest.mock('heic2any', () => ({ window: jest.fn(), }));

At least this worked for me

harleyharl commented 1 year ago

@barisbll I'm experiencing a similar error right now: ReferenceError: Worker is not defined

I've tried adding this in the tests: jest.mock('heic2any', () => ({ window: jest.fn(), }))

Did you just put that line in the body of the test?

alexcorvi commented 1 year ago

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

micabal commented 1 year ago

Same issue when trying to use this library with Svelte. Too bad 😭