Witam, jestem nowy w node.js jak i electron, chciałem przetestować łączenie z bazą danych, jednak otrzymuje błąd
index.html:13 Uncaught ReferenceError: require is not defined
at index.html:13
Nie wiem czemu tak się dzieje, proszę o pomoc.
Zawartość plików
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World Electron App</title>
</head>
<body>
<h1>Electron MySQL Example</h1>
<div id="resultDiv"></div>
<script>
var mysql = require('mysql');
</script>
</body>
</html>
package.json
{
"name": "hello-world",
"version": "1.0.0",
"main": "main.js",
"devDependencies": {
"electron": "^8.2.2"
},
"dependencies": {
"mysql": "^2.18.1"
},
"scripts": {
"start": "electron ."
}
}
main.js
console.log('Start');
const electron = require("electron");
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
const path = require("path");
const url = require("url");
let win;
function createWindow() {
win = new BrowserWindow();
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file',
slashes: true
}));
win.on('close', () => {
win = null;
})
}
app.on('ready', createWindow);