0

I'm getting the error I mentioned above while trying to communicate between electron and react.
In my App.js file: This is causing the error.

const { ipcRenderer, remote } = require('electron');
console.log('electron', ipcRenderer);

I've two electron file. starter(main) & preload.

I've already tried few things.
I addded this in preload file, but still getting that error.

window.ipcRenderer = require('electron').ipcRenderer;

In starter(main) file:

    mainWindow = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
            nodeIntegration: true,
            enableRemoteModule: true,
            contextIsolation: false,
            preload: path.join(__dirname, '/electron-preload.js'),
        },
    });

Added error stack:

TypeError: fs.existsSync is not a function
getElectronPath
http://localhost:3000/static/js/2.chunk.js:423053:10
  423050 | var pathFile = path.join(__dirname, 'path.txt');
  423051 | 
  423052 | function getElectronPath() {
> 423053 |   if (fs.existsSync(pathFile)) {
         |          ^  423054 |     var executablePath = fs.readFileSync(pathFile, 'utf-8');
  423055 | 
  423056 |     if (Object({"NODE_ENV":"development","PUBLIC_URL":"","WDS_SOCKET_HOST":undefined,"WDS_SOCKET_PATH":undefined,"WDS_SOCKET_PORT":undefined,"REACT_APP_BASE_URL":"https://api.staging.fab.delivery/api/v2","REACT_APP_BASE_URL_V3":"https://api.staging.fab.delivery/api/v3","REACT_APP_apiKey":"AIzaSyAmbEZZ5a1YWlvYfeUpOUJZHlkqvRRNA6c","REACT_APP_projectId":"fab-delivery-staging","REACT_APP_messagingSenderId":"354389721186","REACT_APP_appId":"1:354389721186:web:3dd5bde4e7bebc337d513b","REACT_APP_SENTRY_URL":"https://3e076ee5293b41a396ae1a37c18ee399@sentry.levaral.com/37","REACT_APP_SENTRY_ENVIRONNMENT":"staging"}).ELECTRON_OVERRIDE_DIST_PATH) {
View source
(anonymous function)
node_modules/electron/index.js:18
  15 |   }
  16 | }
  17 | 
> 18 | module.exports = getElectronPath()
  19 | 

Chandler Bing
  • 410
  • 5
  • 25
  • can you post the whole error stack? – tromgy Sep 23 '21 at 12:37
  • Looks like this code is running in a browser? In the browser environment Node's `fs` object is not availalble. – tromgy Sep 23 '21 at 13:39
  • It is a bit confusing what code is in which file. Can you make a minimal reproducible example, that shows all the code to reproduce the problem (but does nothing else)? – Darren Cook Sep 23 '21 at 17:14

0 Answers0