samiskin / redux-electron-store

⎋ A redux store enhancer that allows automatic synchronization between electron processes
MIT License
375 stars 32 forks source link

TypeError: fs.existsSync is not a function #52

Open RossAddinall opened 6 years ago

RossAddinall commented 6 years ago

Hi,

I am getting an error: Uncaught TypeError: fs.existsSync is not a function

This link: provides a workaround to the problem. To be entirely honest I don't really understand the cause of the problem, but it certainly works for me.

I am using Electron, React, Redux and Webpack.

The full trace that I get is this:

Uncaught TypeError: fs.existsSync is not a function
    at eval (Y:\testdesigner_MVP\node_modules\electron\index.js:6)
    at Object.<anonymous> (bundle.js:2352)
    at __webpack_require__ (bundle.js:679)
    at fn (bundle.js:89)
    at eval (Y:\testdesigner_MVP\node_modules\redux-electron-store\lib\electronRendererEnhancer.js:82)
    at createStore (Y:\testdesigner_MVP\node_modules\redux\es\createStore.js:51)
    at eval (Y:\testdesigner_MVP\app\lib\stores\renderer_store.js:38)
    at Object.<anonymous> (bundle.js:3937)
    at __webpack_require__ (bundle.js:679)
    at fn (bundle.js:89)

The line of code that I wrote (renderer_store.js:38) is: let renderer_store = createStore(rootReducer, main_store.getState(), enhancer);

which in turn leads (eventually) to electronRendererEnhancer.js:82: var _require = require('electron');

which I presume is derived from renderer-enhancer.js: const { ipcRenderer, remote } = require('electron');

If I change electronRendererEnhancer.js:82 to be: var _require = window.require('electron'); the error goes away.

As I said at the top I don't really understand the root cause of this. If it is appropriate, then perhaps renderer-enhancer.js could be updated to be: const { ipcRenderer, remote } = window.require('electron'); but that may have other consequences I can't see.

If the change is not possible, then hopefully this issue will help others.

J-Cake commented 6 years ago

when I do this, I get a new error: window.require is not a function

samiskin commented 6 years ago

@KlaussMC I think Webpack is causing some weirdness here, might also be related to nodeIntegration: false. I haven't done Electron stuff for a while now so sorry for not being much help 😢

Mazuh commented 5 years ago

I'm still having the same error whenever I write

import { electronEnhancer } from 'redux-electron-store';
abumalick commented 4 years ago

yes when you try to require('electron'); with nodeIntegration: false it dsplay this strange error.

ionalexandrusecara commented 2 years ago

Just want to re-surface this thread. Did anyone end up finding a solution to this issue?

Setting nodeIntegration: true didn't fix it and I also got window.require is not a function. I use electron 10.0.0 if it helps.