Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 231
Vidsify Avatar asked Jul 11 '26 19:07

Vidsify


2 Answers

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")
like image 138
crispengari Avatar answered Jul 13 '26 15:07

crispengari


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

like image 27
Emre Gürbulak Avatar answered Jul 13 '26 15:07

Emre Gürbulak