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

Cannot initialize "screen" module before app is ready #5897

Closed
also opened this issue Jun 7, 2016 · 3 comments
Closed

Cannot initialize "screen" module before app is ready #5897

also opened this issue Jun 7, 2016 · 3 comments

Comments

@also
Copy link

also commented Jun 7, 2016

  • Electron version: v1.2.1
  • Operating system: OS X 10.11.5 (15F34)

The screen documentation starts with

const {app, BrowserWindow, screen: electronScreen} = require('electron');

Running this (even as the only line) in the main process throws an exception:

$ cat screen.js
const {app, BrowserWindow, screen: electronScreen} = require('electron');
$ ./node_modules/.bin/electron screen.js
App threw an error during load
Error: Cannot initialize "screen" module before app is ready
    at Error (native)
    at process.atomBinding (/Users/rberdeen/electron-quick-start/node_modules/electron-prebuilt/dist/Electron.app/Contents/Resources/electron.asar/common/init.js:8:22)
    at Object.<anonymous> (/Users/rberdeen/electron-quick-start/node_modules/electron-prebuilt/dist/Electron.app/Contents/Resources/electron.asar/browser/api/screen.js:2:26)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Module.require (module.js:466:17)
    at require (internal/module.js:20:19)
@zcbenz
Copy link
Member

zcbenz commented Jun 7, 2016

This is an error of the documentation, you have to use the screen module like this:

const electron = require('electron')
app.on('ready', () => {
  const electronScreen = electron.screen
})

@fab1an
Copy link
Contributor

fab1an commented Jul 27, 2017

Is there a way to lift this requirement? I'm writing my electron apps using Kotlin, so I don't have influence on the require calls, they are just generated by the compiler like this:

var app = $module$electron.app;
var screen = $module$electron.screen;
var last = Kotlin.kotlin.collections.last_2p1efm$;
var dropLast = Kotlin.kotlin.collections.dropLast_yzln2o$;
...

@fab1an
Copy link
Contributor

fab1an commented Aug 17, 2017

Also just "requiring" something should definitely not have a sideeffect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants