I am new to Javascript and started to make desktop apps with the help of nodejs and electron. The problem is that I can not use require() outside of my main.js file. But this is shown in some Tutorials I found online.
I searched for hours if I could find a solution, but I could not. I tried to reinstall nodejs, electron and the requirejs module.
<div class="container">
<form>
<div>
<label>Enter Item</label>
<input type="text" id="item" autofocus>
</div>
<button class="waves-effect waves-light btn" type="submit">Add Item</button>
</form>
</div>
<script>
//should give back the item, so that it can be added to the shoppinglist in the main window
const electron = require('electron');
const {ipcRenderer} = electron;
document.querySelector('form').addEventListener('submit', submitForm);
function submitForm(e){
e.preventDefault();
const item = document.querySelector('#item').value;
console.log(ipcRenderer);
ipcRenderer.send('item:add', item);
}
</script>
Expected: When pressing the "Add item" button the entered item should appear in mainWindow
Actual: Nothing happens when pressing the button (Console says: "Uncaught ReferenceError: require is not defined")