Skip to content

Uncaught ReferenceError: process is not defined #18139

Closed

Description

@masoudgs

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

Activity

  1. codebytere commented on May 3, 2019

    @codebytere
    Member

    @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.

  2. masoudgs commented on May 3, 2019

    @masoudgs
    Author

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

  3. codebytere commented on May 3, 2019

    @codebytere
    Member

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

  4. phamkimtho commented on Sep 27, 2019

    @phamkimtho

    Thank you very much. Now I can solved my problem!

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

  5. swapnilvaidankar commented on Nov 6, 2019

    @swapnilvaidankar

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

  6. schmorrison commented on Jan 17, 2020

    @schmorrison

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

    In your electron apps main.js file, check the project package.json file -- the "main" parameter shows the files path

  7. cawoodm commented on Dec 27, 2020

    @cawoodm

    Note contextIsolation: false now replaces nodeIntegration: true.

  8. raphael10-collab commented on Feb 11, 2021

    @raphael10-collab

    @codebytere While keeping nodeIntegration to false how to still access process object?

  9. eXhumer commented on Mar 3, 2021

    @eXhumer

    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.

  10. fortypercenttitanium commented on Mar 4, 2021

    @fortypercenttitanium

    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.

    THANK YOU SO MUCH! I've been spinning my wheels all day trying to figure out why not even following electron's own quick start guide was working for me!

  11. ohmygod481999 commented on Mar 11, 2021

    @ohmygod481999

    Me too, quick start doesn't work. Uncaught ReferenceError: process is not defined x 3

  12. hbieler commented on Mar 11, 2021

    @hbieler

    I found same problem - just by doing the beginners samples.
    npm 7.6.2
    node v15.11.0
    on Windows 20H2

  13. rhllor commented on Mar 11, 2021

    @rhllor

    mee too, i follow quickstart but i got "Uncaught ReferenceError: process is not defined".

    image

    node v14.16.0
    npm v6.14.11

    I missing some requirement?

  14. siyavashg commented on Mar 11, 2021

    @siyavashg

    update your main.js as follows:

    function createWindow () {
      const win = new BrowserWindow({
        width: 600,
        height: 600,
        webPreferences: {
          nodeIntegration: true,
          contextIsolation: false
        }
      })
    
  15. hbieler commented on Mar 11, 2021

    @hbieler

    Thanks for quick help :-)
    this solved the issue in the simple sample ;-)

  16. siyavashg commented on Mar 12, 2021

    @siyavashg

    Thanks for quick help :-)
    this solved the issue in the simple sample ;-)
    No problem!

  17. nilslindemann commented on Mar 13, 2021

    @nilslindemann

    @codebytere

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

    But it was not, and the latest breaking change ( contextIsolation: false ) is not in the official docs.

  18. soymikey commented on Mar 17, 2021

    @soymikey

    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.

    thank you so much , i have created so many new project from scratch until i have seen you answer. cheers mate~~

  19. visionari-labs commented on Apr 25, 2021

    @visionari-labs

    I thought for security purposes, we should disable nodeIntegration and enable contextIsolation... I ran into this issue when I tried to run a packaged Electron app on my other Macbook. Is this safe to run on the main window?

  20. arnoldmartinez commented on Mar 5, 2022

    @arnoldmartinez

    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');
    });

  21. m4xlmum commented on Apr 8, 2022

    @m4xlmum

    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'); });

    It done, Thanks. From Electron v18.0.1

  22. ndkk commented on Jun 24, 2022

    @ndkk

    The key:
    webPreferences: {
    nodeIntegration: true,
    contextIsolation: false
    }

    Thanks !

    "I am using Node.js 16.14.2, Chromium 102.0.5005.63, and Electron 19.0.4“

  23. IshmeetSingh06 commented on Oct 20, 2022

    @IshmeetSingh06

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions