electron: Uncaught ReferenceError: process is not defined

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • I agree to follow the Code of Conduct that this project adheres to.

Issue Details

  • Electron Version: 5.0.0
  • Operating System: Arch Linux

Expected Behavior

I’d expect to access process object in my renderer process

Actual Behavior

Chrome dev tools throw ReferenceError while accessing to process object.

Uncaught ReferenceError: process is not defined

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 9
  • Comments: 26 (2 by maintainers)

Most upvoted comments

@msudgh nodeIntegration is turned off by default in 5, so you’ll need to enable it via:

const { BrowserWindow } = require('electron')
let win = new BrowserWindow({
  webPreferences: {
    nodeIntegration: true
  }
})

which we caution against, or add it via preload script.

Note contextIsolation: false now replaces nodeIntegration: true.

I needed to use both, using only contextIsolation: false / nodeIntegration: true doesn’t fix the issue. This affects the quick start guide as only nodeIntegration: true was mentioned there.

update your main.js as follows:

function createWindow () {
  const win = new BrowserWindow({
    width: 600,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
      contextIsolation: false
    }
  })

Note contextIsolation: false now replaces nodeIntegration: true.

If i use both of the nodeIntegration:true and constextIsolation:false it shows up a error which is: image

If i turn both of them true it still get the error: process is not defined

Using the quick start (https://www.electronjs.org/docs/tutorial/quick-start), copied exact code, but still doesn’t work 😦

Code:

const { app, BrowserWindow } = require("electron");

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
    },
  });

  win.loadFile("index.html");
}

app.whenReady().then(createWindow);

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});

app.on("activate", () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});

Error:

Uncaught ReferenceError: process is not defined x 3, because checking Node, Chromium, Electron versions

@msudgh nodeIntegration is turned off by default in 5, so you’ll need to enable it via:

const { BrowserWindow } = require('electron')
let win = new BrowserWindow({
  webPreferences: {
    nodeIntegration: true
  }
})

which we caution against, or add it via preload script.

Where to add this above code?

@codebytere Thanks. it’d be better to update docs. this functionality existed in previous versions.

Wow. Works like a charm. I would request ElectronJS Team to please update the docs and add this, or totally remove the need to use contextIsolation with nodeIntegration

@msudgh this information was presented both in release notes and in breaking change documentation leading up to and including the stable release 😃

Thanks it worked for me, you don’t that how happy now I am thank you very very much…

I did resolve it putting contextIsolation to false.

// 1. import electron objects const { app, BrowserWindow } = require(‘electron’);

// 2. reserve a reference to window object let window;

// 3. wait till application started app.on(‘ready’, () => { // 4. create a new window window = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true, contextIsolation: false } }); // 5. load window content window.loadFile(‘index.html’); });

Thanks for quick help 😃 this solved the issue in the simple sample 😉