Open Andrew-web-coder opened 5 months ago
I have never used what you are using :( maybe write
var window = {};
before loading UPNG.js
I am trying to load it inside the worker using importScripts
and it is not possible to define window object before loading the script.
If only there was a check in the code if window
exists...
But are you sure that then, UPNG.js will work inside a worker? You could rewrite UPNG.js manually in a notepad.
Yes, it works if I download this code - https://greggman.github.io/doodles/js/UPNG.js
. It is taken from https://webglfundamentals.org/webgl/lessons/webgl-qna-how-to-load-images-in-the-background-with-no-jank.html
I believe it is the same code as in this repo (slightly different, maybe an older version) and, as you can see, it does not contain the unnecessary Make available for import
code snippet that breaks usage in the worker.
I made UPNG.js to be used in a web browser. Maybe ask that guy to make you a version that works in your environment?
You see, if I download directly from https://github.com/photopea/UPNG.js/blob/master/UPNG.js it works fine, too. The problem is with that extra code that is added to the version that is hosted on CDN. I just wanted to use your code (and thank you so much for your work) from jsdeliver, because I already use other scripts from there.
I got this error while trying to use it in non-window environment from jsdelivr:
ReferenceError: window is not defined
Any tips on how to use it from jsdelivr?
The file I am trying to use:
https://cdn.jsdelivr.net/npm/upng-js@2.1.0/UPNG.min.js
But even this file:
https://cdn.jsdelivr.net/npm/upng-js@2.1.0/UPNG.js
contains
else {window.UPNG = UPNG;}
and I do not understand why, because source code does not contain that code :/