electron: [v0.36.2 mac] require('electron').app undefined
require('electron').app not work but require('app') is okay.
Just tried https://github.com/atom/electron-quick-start , and also got same error.
seems require(‘electron’).* all missing.
change code to this:
'use strict';
const electron = require('electron');
// Module to control application life.
const app = electron.app;
console.log(app);
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
got following result:
$ npm start
> electron-quick-start@1.0.0 start /Users/hialanMacAir/Work/electron-quick-start
> electron main.js
undefined
App threw an error when running [TypeError: Cannot read property 'on' of undefined]
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 9
- Comments: 38 (7 by maintainers)
Hi maxfarseer, you can access the “app” using require(“electron”).remote.app. Using the example you referenced:
@maxfarseer
try, writing
const electron = require(‘electron’) var remote = require(‘electron’).remote const app = remote.app
in rederer.js
As of today (late Aug 2017), I find that
electron.appworks from the main process, but not from a renderer process, andelectron.remote.appworks from a renderer process, but not from the main process. For example:Do not install node-electron ( https://www.npmjs.com/package/electron ) which is belong to another project. Just remove it and it will work.
npm remove electron(for local)npm remove electron -g(for global)I don’t understand how this fix removing electron locally and globally can work, so how we are going to use “npm start” or run the app after this? :S I’m having this issue.
These modules are no longer available directly via
requirein order to prevent name collisions with other third party modules as discussed in #387.Electron v0.35.0 started issuing deprecation warnings about
require('app'), and Electron v1.0.0 removed the ability torequire('app')completely, so if you don’t want to update your old code downgrade to the last release before v1.0.0.I’m sorry to revive this, but I am having this issue on Mac OSX Sierra as well.
Here’s my environment:
electronpackage)package.json
index.js
Then I run:
What is the solution to resolve this?
@Pablodotnet I suggest posting your issue in https://discuss.atom.io/c/electron along with the full error information.
Yes I know that, that’s how I’m running the app and I have electron installed there in my app folder with npm install electron. But you are saying the error I’m having of the ‘on’ issue solves removing locally and globally so doing that, the script will not run because electron isnt installed neither globally and locally
@trusktr Sounds like you’re running
node src/index.jsinstead ofelectron src/index.jsEither that or the
ELECTRON_RUN_AS_NODEenv var is set 🤔I solve in my case changing the package.json was:
“scripts”: { “test”: “echo “Error: no test specified” && exit 1”, “start”: “node index.js” },
and I changed to:
“scripts”: { “start”: “electron .” },
Waoh, Very Thanks Point this Out!!!
@jinfagang
const {remote} = require('electron').remoteis the equivalent ofconst remote = require('electron').remote.remote, you need to useconst {remote} = require('electron').Im sorry if I didn’t explain well the first time, I’m having the same problem as hialan was having,
App threw an error when running [TypeError: Cannot read property 'on' of undefined]When running npm start, the console in the electron app keeps giving me that error.
@Pablodotnet this doesn’t really have anything to do with installing electron locally or globally. But if you install Electron locally you can start your app with
npm startchanging/adding thestartNPM script to yourpackage.jsonand set it to runelectron .orelectron path/to/main.js, e.g.