react-image-lightbox icon indicating copy to clipboard operation
react-image-lightbox copied to clipboard

Uncaught ReferenceError: global is not defined

Open LuanEdCosta opened this issue 3 years ago • 4 comments

Reporting a Bug?

I'm using Vite (it is a build tool) and got this error:

Uncaught ReferenceError: global is not defined at getWindowWidth (react-image-lightbox.js?v=afb60f06:1711:3) at ReactImageLightbox2.getLightboxRect (react-image-lightbox.js?v=afb60f06:2039:16) at ReactImageLightbox2.render (react-image-lightbox.js?v=afb60f06:2757:26) at finishClassComponent (chunk-E4KBW6RW.js?v=afb60f06:14537:39) at updateClassComponent (chunk-E4KBW6RW.js?v=afb60f06:14502:32) at beginWork (chunk-E4KBW6RW.js?v=afb60f06:15701:22) at HTMLUnknownElement.callCallback2 (chunk-E4KBW6RW.js?v=afb60f06:3451:22) at Object.invokeGuardedCallbackDev (chunk-E4KBW6RW.js?v=afb60f06:3476:24) at invokeGuardedCallback (chunk-E4KBW6RW.js?v=afb60f06:3510:39) at beginWork$1 (chunk-E4KBW6RW.js?v=afb60f06:18987:15)


I believe that this caused the problem:

src/util.js

image

I don't have the global variable defined.

LuanEdCosta avatar Jun 24 '22 17:06 LuanEdCosta

I'm using Vite(v2.9.9), got same issue

dannyxu2015 avatar Jul 07 '22 12:07 dannyxu2015

@LuanEdCosta , try this, it worked for me! Just add <script>window.global = window;</script> to your index.html

dannyxu2015 avatar Jul 07 '22 13:07 dannyxu2015

Nice solution! Thanks.

LuanEdCosta avatar Jul 07 '22 13:07 LuanEdCosta

Gota same issue with Vite 3.0.5. <script>window.global = window;</script> fixed it

valkedev avatar Aug 16 '22 08:08 valkedev