react-electron-browser-view
react-electron-browser-view copied to clipboard
Can't import npm package into program
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
I am also having this issue on the import, the exact same for me.
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: