npmnode.js95% confidence\u2191 40

TypeError: window.require is not a function

Full error message
Im trying to build an electron app and want to use window.require. Unfortunately the compiler says "TypeError: window.require is not a function". Ironically require works only in main.js.

Here the code Im trying to run:

const electron = window.require('electron')
const low =  window.require('lowdb')
const FileSync = window.require('lowdb/adapters/FileSync')

I read in another post that somebody have had the same problem and it was fixed by adding this code into the .html file:

    <script type="text/javascript" src="../../../Gehaltseinstellungen_Hinzufügen.js">
        window.nodeRequire = require;
        delete window.require;
        delete window.exports;
        delete window.module;
    </script>

Also the author said using "nodeRequire" instead of require would solve the problem but it doesn't...

Another option I read about is that the NodeIntegration is set to false while the rendering process is activated, but I don't know how to activate Node while rendering.

It is unclear what version of Electron you are using. The syntax you are using is non-standard. First – if you are using Electron 5.0, nodeIntegration is false by default in BrowserWindows so you need to specify it explicitly when you create your window: mainWindow = new BrowserWindow({ width: 800, height: 600, webPreferences: { nodeIntegration: true } }) Given the above, the syntax below works fine (i.e. no 'window' reference needed): const { ipcRenderer, remote } = require('electron');

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/0f02736636c00ed746e27dd2bfaa0c0f04b35eecd09b1e0b793b88fac96f1366
hash \u00b7 0f02736636c00ed746e27dd2bfaa0c0f04b35eecd09b1e0b793b88fac96f1366
TypeError: window.require is not a function — DepScope fix | DepScope