{"id":753,"hash":"0f02736636c00ed746e27dd2bfaa0c0f04b35eecd09b1e0b793b88fac96f1366","pattern":"TypeError: window.require is not a function","full_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.\n\nHere the code Im trying to run:\n\nconst electron = window.require('electron')\nconst low =  window.require('lowdb')\nconst FileSync = window.require('lowdb/adapters/FileSync')\n\nI read in another post that somebody have had the same problem and it was fixed by adding this code into the .html file:\n\n    <script type=\"text/javascript\" src=\"../../../Gehaltseinstellungen_Hinzufügen.js\">\n        window.nodeRequire = require;\n        delete window.require;\n        delete window.exports;\n        delete window.module;\n    </script>\n\nAlso the author said using \"nodeRequire\" instead of require would solve the problem but it doesn't...\n\nAnother 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.","ecosystem":"npm","package_name":"node.js","package_version":null,"solution":"It is unclear what version of Electron you are using. The syntax you are using is non-standard.\n\nFirst – 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:\n\nmainWindow = new BrowserWindow({\n  width: 800,\n  height: 600,\n  webPreferences: {\n    nodeIntegration: true\n  }\n})\n\nGiven the above, the syntax below works fine (i.e. no 'window' reference needed):\n\nconst { ipcRenderer, remote } = require('electron');","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/56091343/typeerror-window-require-is-not-a-function","votes":40,"created_at":"2026-04-19T04:51:36.212935+00:00","updated_at":"2026-04-19T04:51:36.212935+00:00"}