react-electron-browser-view icon indicating copy to clipboard operation
react-electron-browser-view copied to clipboard

Can't import npm package into program

Open twendykirn opened this issue 4 years ago • 2 comments

Hi, I just downloaded react-electron-browser-view and I can't import (or require) this package. I added only this line of code: import BrowserView from 'react-electron-browser-view'

And got this: TypeError: fs.existsSync is not a function getElectronPath C:/electron-browser-react/node_modules/electron/index.js:7 4 | var pathFile = path.join(__dirname, 'path.txt') 5 | 6 | function getElectronPath () { 7 | if (fs.existsSync(pathFile)) { 8 | var executablePath = fs.readFileSync(pathFile, 'utf-8') 9 | if (process.env.ELECTRON_OVERRIDE_DIST_PATH) { 10 | return path.join(process.env.ELECTRON_OVERRIDE_DIST_PATH, executablePath) View compiled

Electron 9.0.4

twendykirn avatar Jun 14 '20 11:06 twendykirn

I am also having this issue on the import, the exact same for me.

MattrhornCT avatar Jun 17 '20 22:06 MattrhornCT

I had the same issue... After some googling it seems like its an issue with Electron itself. The solution is changing: import BrowserView from 'react-electron-browser-view' to: const ElectronBrowserView = window.require('react-electron-browser-view').default;` That results in another error:

window.require is not a function

and to resolve that you should add webPreferences: { nodeIntegration: true, } to your electron main window. Sources:

galsol avatar Jul 26 '20 18:07 galsol