Hello i am new to electron. I am tring to use npm modules in renderer.js file but it keeps giving me:
Uncaught ReferenceError: require is not defined
I checked other questions on stackoverflow this for example:
Electron require() is not defined
i tried the solution on there but did not solved my problem
main.js file
// MODULES
const {app, BrowserWindow} = require('electron')
const path = require('path')
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
})
win.loadFile('index.html')
}
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if(BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js'></script>
<link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css'>
<title>Electron!</title>
</head>
<body>
<div class="text-center container">
<div class="form-group">
<label class="p-5" for="link">Video Link</label>
<input type="text" class="form-control" id="link" placeholder="enter youtube link!">
</div>
<button type="submit" class="btn btn-primary" onclick="searchURL()">Enter!</button>
</div>
<script src="./renderer.js"></script>
</body>
</html>
renderer.js
const fs = require('fs');