heic2any
heic2any copied to clipboard
Web workers
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?
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
I believe the author meant the library uses web workers to process images.
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 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?
The library requires a full browser environment with DOM api to work
Same issue when trying to use this library with Svelte. Too bad 😭