heic2any icon indicating copy to clipboard operation
heic2any copied to clipboard

Web workers

Open KNazarenko opened this issue 3 years ago • 3 comments

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?

KNazarenko avatar Mar 19 '21 12:03 KNazarenko

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

Tim-mhn avatar Aug 23 '21 01:08 Tim-mhn

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

chebum avatar Dec 10 '21 19:12 chebum

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

barisbll avatar Aug 22 '22 12:08 barisbll

@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?

harleyharl avatar Oct 10 '22 01:10 harleyharl

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

alexcorvi avatar Mar 29 '23 09:03 alexcorvi

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

micabal avatar May 26 '23 10:05 micabal