frontend-collective / react-image-lightbox

React lightbox component
https://frontend-collective.github.io/react-image-lightbox/
MIT License
1.29k stars 357 forks source link

Uncaught ReferenceError: global is not defined #634

Closed LuanEdCosta closed 1 year ago

LuanEdCosta commented 2 years ago

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.

dannyxu2015 commented 2 years ago

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

dannyxu2015 commented 2 years ago

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

LuanEdCosta commented 2 years ago

Nice solution! Thanks.

valkedev commented 2 years ago

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