Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"require" not working in a seperate file ? #18388

alexs7 opened this issue May 21, 2019 · 3 comments


None yet
3 participants
Copy link

commented May 21, 2019

I have a straightforward main.js file as below:

const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')

let win

function createWindow () {
  // Create the browser window.
  win = new BrowserWindow({ width: 1280, 
                            height: 720, 
                            nodeIntegration: true, 
                            resizable: false,
                            maximizable: false })

  // and load the index.html of the app.

  // Open the DevTools.

  // Emitted when the window is closed.
  win.on('closed', () => {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    win = null

app.on('ready', createWindow)

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {

app.on('activate', () => {
  if (win === null) {

I also have an init.js file that I only have 1 line of code in it.

const fs = require('fs');

Now I have tried and searched online for multiple solutions but nothing works so I am raising an issue here.

I tried this aswell: - with no success.

I keep getting Uncaught ReferenceError: require is not defined


This comment has been minimized.

Copy link

commented May 21, 2019

Thanks for reaching out!

We require the template to be filled out on all new issues and pull requests. We do this so that we can be certain we have all the information we need to address your submission efficiently. This allows the maintainers to spend more time fixing bugs, implementing enhancements, and reviewing and merging pull requests.

Thanks for understanding and meeting us half way 😀


This comment has been minimized.

Copy link

commented May 22, 2019

I finally got it sorted nodeIntegration: true should have been in webPreferences block!

@alexs7 alexs7 closed this May 22, 2019


This comment has been minimized.

Copy link

commented May 25, 2019

I also starting seeing problems with require this morning. Not sure how it's been working fine for years now.

I also didn't have nodeIntegration: true set. I set it and it now works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.