React and Electron with Draft.js: "Global is not defined"

Viewed 3479

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'?

1 Answers
Related