react-image-lightbox
react-image-lightbox copied to clipboard
Uncaught ReferenceError: global is not defined
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

I don't have the global variable defined.
I'm using Vite(v2.9.9), got same issue
@LuanEdCosta , try this, it worked for me!
Just add
<script>window.global = window;</script>
to your index.html
Nice solution! Thanks.
Gota same issue with Vite 3.0.5. <script>window.global = window;</script> fixed it