'TypeError: fs.existsSync is not a function' ReactJS and Electron

14,564

Solution 1

I was facing the same problem and I've spend half of my day looking for the solution Instead of importing or requiring electron in the App.js as

import * as electron from 'electron'

OR

const electron = require("electron")

Go ahead and import electron in your App.js as follows using the window object

const electron = window.require("electron")

Solution 2

I was found this issue : https://github.com/electron/electron/issues/7300

Can you change electron import like this:

const electron = window.require('electron') and use : electron.remote

Share:
14,564

Related videos on Youtube

Vidsify
Author by

Vidsify

Avid web developer from the UK

Updated on June 04, 2022

Comments

  • Vidsify
    Vidsify almost 2 years

    I'm having an issue where I'm getting a TypeError: fs.existsSync is not a function error when my React App loads.

    I'm trying to add functionality to my custom MacOS buttons, however, when I seem to import {remote} from 'electron', I get that error.

    This is the component source code: https://sourceb.in/1ffad505cd.jsx This is the error generated in the console: https://sourceb.in/8c01058284.txt

    It looks to be an Electron issue but I can't seem to figure out why.

    Any help or advice would be much appreciated.

    • Virinchi Manepalli
      Virinchi Manepalli almost 3 years
      i resolved this error, here is the link
  • Vidsify
    Vidsify over 4 years
    Its saying TypeError: window.require is not a function
  • tpikachu
    tpikachu over 4 years
    Create window like this mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true } })
  • tpikachu
    tpikachu over 4 years
    Did you add webPreferences with nodeIntegration when your BrowserWindow is being created?
  • Vidsify
    Vidsify over 4 years
    Must I have missed that part. So it's now working but I am having issues changing back from fullscreen mode to maximized mode. Any ideas? macButtonsMaximise = () => { const currentWindow = electron.remote.getCurrentWindow() if (currentWindow.isMaximized) { currentWindow.setFullScreen(true) } else { currentWindow.setFullScreen(false) } }
  • Emre Gürbulak
    Emre Gürbulak over 4 years
    Can yo tell me , what did you see for currentWindow on console when you change back from fullscreen mode to maximized mode.
  • uhetz
    uhetz about 3 years
    Note, that set-in preference nodeIntegration to true (as mentioned @tpikachu) is against the electron's security guide. electronjs.org/docs/tutorial/…