I have created react app after that i added electron module to react app.Actually i am trying open OS browser from electron container which has react app.I am using latest electron version(12). I tried so many ways but i am not able to figure it out.
code:
const electron = require("electron");
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const isDev = require("electron-is-dev");
const path = require("path");
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
enableRemoteModule:true,
}
})
mainWindow.loadURL("http://localhost:3000");
mainWindow.on("closed", () => {
mainWindow = null;
});
}
app.on("ready", createWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (mainWindow === null) {
createWindow();
}
});
import React from "react";
const electron = window.require("electron");
function App() {
const openBrowser = () => {};
return <div onClick={openBrowser}>{isRenderer ? "Electron" : "react"}</div>;
}
export default App;
×
TypeError: window.require is not a function
Module.<anonymous>
src/App.tsx:3
1 | import React from "react";
2 | var isRenderer = require("is-electron-renderer");
> 3 | const electron = window.require("electron");
4 |
5 | function App() {
6 | const openBrowser = () => {};