Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: window is not defined [CDN] #91

Open
Andrew-web-coder opened this issue Jun 9, 2024 · 6 comments
Open

ReferenceError: window is not defined [CDN] #91

Andrew-web-coder opened this issue Jun 9, 2024 · 6 comments

Comments

@Andrew-web-coder
Copy link

Andrew-web-coder commented Jun 9, 2024

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/[email protected]/UPNG.min.js

But even this file:

https://cdn.jsdelivr.net/npm/[email protected]/UPNG.js

contains else {window.UPNG = UPNG;} and I do not understand why, because source code does not contain that code :/

@Andrew-web-coder Andrew-web-coder changed the title ReferenceError: window is not defined ReferenceError: window is not defined [CDN] Jun 9, 2024
@photopea
Copy link
Owner

photopea commented Jun 9, 2024

I have never used what you are using :( maybe write

var window = {};

before loading UPNG.js

@Andrew-web-coder
Copy link
Author

Andrew-web-coder commented Jun 10, 2024

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...

@photopea
Copy link
Owner

But are you sure that then, UPNG.js will work inside a worker? You could rewrite UPNG.js manually in a notepad.

@Andrew-web-coder
Copy link
Author

Andrew-web-coder commented Jun 10, 2024

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.

@photopea
Copy link
Owner

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?

@Andrew-web-coder
Copy link
Author

Andrew-web-coder commented Jun 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants