electron: Uncaught ReferenceError: require is not defined
- Electron Version: from 5.0.0-beta.5 to 5.0.0-beta.1
- Operating System: macOS 10.14.3
- Last Known Working Electron version:: 4.0.7
Problem
Build and pack passed well, but after run app, I see an error in console Uncaught ReferenceError: require is not defined - at Object.electron - at __webpack_require__.
Screenshots
Additional Information
We use Typescript, electron-builder, webpack.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 19 (2 by maintainers)
Commits related to this issue
- Upgrade electron The fix in main.js was done because of this: https://github.com/electron/electron/issues/17241 — committed to thameera/toolbox by thameera 5 years ago
- fix: Make `npm start` work again See electron/electron#17241 `nodeIntegration` now defaults to `false` so you'd just get an error message like > Uncaught ReferenceError: require is not defined — committed to mongodb-js/compass-connect by imlucas 4 years ago
- Fix https://github.com/electron/electron/issues/17241 — committed to vlewin/electron-tray-player by vlewin 4 years ago
in your index.js
const w = new BrowserWindow({ webPreferences: { nodeIntegration: true } })
actually i added nodeIntergration = true but dosent work still
Assuming electron 12.0.0
set
contextIsolation: falseSomething like…
reference: https://stackoverflow.com/a/66455544/4097181
Thanks! Have solved my problem.
👋 Thanks for opening your first issue here! If you’re reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
To help make it easier for us to investigate your issue, please follow the contributing guidelines.
The default for nodeIntegration changed from true to false as per our breaking changes document.
@brntsllvn Adding
Works like a charm!! Thing is, do these other properties affect your application in any way?
Regards,
Need to change webPreferences.nodeIntegration to true when new BrowserWindow
mainWindow = new BrowserWindow({ width: 1000, height: 600, webPreferences: { nodeIntegration: true } });https://github.com/electron/electron/blob/master/docs/api/breaking-changes.md
It didn’t work for me because
webPreferences.contextIsolationwas set to true. Be careful when setting that option to false though https://www.electronjs.org/docs/tutorial/context-isolation#security-considerations.setting
nodeIntegrationto true is the easy way, bu keeping it false is more secure as documentation tells, I ve found this https://stackoverflow.com/questions/52236641/electron-ipc-and-nodeintegration that may help future readers.