Navigator / Document is null


I’m trying to install Codemirror in Electron. While installing the modules work, the module itself doesn’t work, because Navigator and Document are null, so I guess I do a require of the codemirror module in the wrong place.

Right now, the main.js looks like this:

 'use strict';
  const electron = require('electron');
  const codemirror = require("codemirror"); // <--- the codemirror change
  const app =;  // Module to control application life.

But the codemirror uses the navigator and the document, for which I get an error: ReferenceError: document is not defined. So, my guess is: I include the codemirror module in the wrong place.

However, what I haven’t figured out yet, is: what is the correct place?

Thanks, Erik


You need to require codemirror from the renderer process (e.g. from index.html or a script included there). The main process does not have access to web APIs.


Ah, thanks! I was confused about how to access the different processes. Thanks, that will work!