Cannot find module 'app'


#1

I get this error when I update to electron-prebuilt version 1.0.1 and try to start the app.


#2

I’m having a similar problem.


#3

In 1.0 there is only a single require called electron that all modules are properties on.

So instead of require('app') it is require('electron').app.

Is there a migration document out there somewhere?

There is an article here: http://electron.atom.io/blog/2015/11/17/electron-api-changes

And also a few minor changes mentioned in: https://github.com/electron/electron/releases/tag/v1.0.0


#4

My code is already structured as such. In fact, I don’t require('app') anywhere in my code.

The top of my file looks like this.

/* jshint node: true */
/* jshint esversion: 6 */

'use strict';

const electron = require('electron');
const path = require('path');

require('electron-reload')(__dirname, {
  electron: require('electron-prebuilt')
});
// Module to control application life.
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;

#5

I am having same issue. Have you figured out a fix?


#6

Check your dependencies! I have found out the errors were comning from electron-window-state and electron-squirrel-startup, which had an older reuqire usage of app module (in fact they were using require('app'), now unsupported)
I updated those dependencies and the errors were gone.


#7

This fixed my problem:
var electron = require(‘electron’);
var app = electron.app;
var BrowserWindow = electron.BrowserWindow;


var mainWindow = null;


app.on(‘ready’, function(){
mainWindow = new BrowserWindow({
width: 800,
height: 600
})
})


#8

This error occurs because npm is looking for a folder app defined in package.json file

Change

“scripts”: {
“start”: “electron ./app”,
}

to

"scripts": {
    "start": "electron .",
}

#9

const app=electron.app;


#10

still facing same issue. can you please share any working example?


#11
const {app} = require('electron');
const {BrowserWindow} = require('electron');

This solved it for me.


#12

This can be shortened to

const {app, BrowserWindow} = require("electron");

#13

This fixed my problem. Thanks.


#14

I am having the same issue with electron . command.

  • This the code which I am using in my app.js file.
"use strict";

// const electron = require("electron");
// Module to control application life.
const { app } = require("electron");
// Module to create native browser window.
const { BrowserWindow } = require("electron");

  • error I am getting is this:
❯  npm start

> simple-electron@1.0.0 start /home/lalit/Desktop/Github/Electron/simple-electron/simple-electron-react
> electron .

App threw an error during load
Error: Cannot find module 'app'
    at Module._resolveFilename (module.js:485:15)
    at Function.Module._resolveFilename (/home/lalit/Desktop/Github/Electron/simple-electron/simple-electron-react/node_modules/electron-prebuilt-compile/node_modules/electron/dist/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/lalit/Desktop/Github/Electron/simple-electron/simple-electron-react/node_modules/electron-reload/main.js:1:166)
    at Object.<anonymous> (/home/lalit/Desktop/Github/Electron/simple-electron/simple-electron-react/node_modules/electron-reload/main.js:52:3)
    at Module._compile (module.js:569:30)
    at Object.require.extensions.(anonymous function) [as .js] (/home/lalit/Desktop/Github/Electron/simple-electron/simple-electron-react/node_modules/electron-compile/lib/require-hook.js:77:14)
    at Module.load (module.js:503:32)