"TypeError: window.require is not a function" in Electron/Angular sample app

Viewed 2401

So I’m very new to Angular and Electron, and I've been having difficulties getting things to work. I've been looking for sample apps so that I could have a starting point that I could understand, and I came across this: https://developer.okta.com/blog/2019/03/20/build-desktop-app-with-angular-electron

I've been following it, and at the point where I first run npm run electron the window opens but stays empty, and in the devtools console I find Uncaught TypeError: window.require is not a function.

I had made just some minor adjustments (making some types explicit) because initially it wouldn't compile, but nothing that should change anything about this.

I have done some searches and for what I understand it might have something to do with

const electron = (<any>window).require('electron');

not being in electron/main.ts, but I genuinely don't know what I'm supposed to do. I tried adding webPreferences: {nodeIntegration: true} in the BrowserWindow constructor, but to no avail.

I'm at a loss; I don't understand the framework enough to resolve it myself.

Edit: npm v6.14.8, node v10.19.0, electron v12.0.1

2 Answers

It seems to me that if you use this code instead of the other code, it might work:

const electron = require("electron");

If this does not solve your problem, I would switch to vanila js

you can take a look over this repo from GitHub. you'll be able to understand the whole concept between angular and electron boostraping.

Related