Can anyone explain me why this code is not working? I tried to require the renderer in file protocol (without express static server) and it was fine, but when i do this with http protocol i got Uncaught Error: Cannot find module './renderer' !
Is there any way to require custom modules in http?
Thanks ...
Structure
- project
+ node_modules
- app.js
- index.html
- package.json
- renderer.js
app.js
const { app, BrowserWindow } = require('electron');
const express = require('express');
const path = require('path');
const url = require('url');
const server = express();
server.use(express.static(__dirname));
app.on('ready', () => server.listen(3000, createWindow));
function createWindow() {
let win = new BrowserWindow({ width: 800, height: 600 });
win.loadURL(url.format({
protocol: 'http',
hostname: 'localhost',
port: 3000
}));
win.webContents.openDevTools();
win.on('closed', function () {
win = null;
app.quit();
});
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<div id="root"></div>
<script>
require('./renderer');
</script>
</body>
</html>
renderer.js
var root = document.getElementById('root');
root.innerHTML = 'Hello, World !';
- Electron Version : 1.7.10
- Operating System : Windows 10