sindresorhus/electron-util

Can't import in renderer process

ash0x0 opened this issue · 9 comments

I'm not sure why but this is not found in renderer process. I'm using 0.14.2 with electron 11.3.0 and node 14.5.4. I've tried it with a fresh project too and no joy.
I get the usual Uncaught TypeError: fs.existsSync is not a function with const {is} = require('electron-util').
Is this mismatched versions or an issue with my use.

EDIT: This also happens when using the included electron-is-dev. Using standalone electron-is-dev@2.0.0 works fine so long as electron-util isn't installed. If electron-util is installed then const {isDev} = require('electron-is-dev') defaults to the included electron-is-dev@1.2.0 and produces the same error.

You need to enable the enableRemoteModule option to be able to use it directly in the renderer process.

Duplicate of #36

You need to enable the enableRemoteModule option to be able to use it directly in the renderer process.

I do have it enabled ofc, along with nodeIntegration. Still no joy.

Do you have a build process? Usually, these kinds of problems are caused by an incorrectly configured Webpack config.

Yeah that was my thinking too. I use create react app with default config. I tried with a fresh cra project and it doesn't work there either.
electron-is-dev stopped working today too and it was working fine until yesterday, which makes me suspect this could be related to node version or another native dependency, something that resides outside node_modules which would explain why electron-is-dev and electron-util don't work with new projects either.
Mind you, this is in the renderer process only, main still works fine. Electron old remote and @electron/remote both work fine as well and right now I'm getting around this issue by using remote globals.

It could also be an update to cra or react-scripts that broke things. I haven't looked into that. I'll try without cra now.

This seems to be an issue with my environment. On this particular machine (Windows 1909, node 14.5.4) the behavior is the same everywhere. Tried vanilla, react, vue renderers, with build and without, different versions of electron in fiddle, everything.
I tried on a different machine (Ubuntu 20.04, node 14.5.4) and it's working fine, travis builds correctly too with the same node version on windows.
Are there any conflicts you're aware of that could cause this weird issue?

No idea what happened here, fixed by reinstalling node and everything on top.

hm, i have the same Problem.

index.js:7 Uncaught TypeError: fs.existsSync is not a function
    at getElectronPath (index.js:7)