There is a similar question raised here: Uncaught ReferenceError: global is not defined at Object../node_modules/fbjs/lib/setImmediate.js
And there are two answers on that question that both seem confident they can solve it. The problem for me is--no explanation of how to implement the answers is given.
Basically, I have an electron app incorporating React, everything works fine until I try to implement draft.js into the project. I get the following error:
app.js:19805 Uncaught ReferenceError: global is not defined
The log points me to a line in the babel/webpack-compiled app.js:
module.exports = global.setImmediate;
The specific thing that causes it is narrowed down to an import statement:
import {Editor, EditorState} from 'draft-js';
One of the answers in the linked question above says to add a global object on the window:
(window as any).global = window;
What I can't figure out is... what does that mean? In my main.js file, where I create the window (it's just the one window for the entire app) trying to do this throws an error seemingly no matter where I try to do it, and I can't seem to find any reference to defining 'global' at all. Where am I meant to define 'global'?
global got renamed to globalThis in the tc39 proposal https://github.com/facebook/fbjs/issues/290
just add this to index.html that's how i got it fixed
<script>
const global = globalThis;
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With