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 screen module before app ready causes error #16168

Closed
timfish opened this issue Dec 21, 2018 · 2 comments · Fixed by #17496
Closed

require screen module before app ready causes error #16168

timfish opened this issue Dec 21, 2018 · 2 comments · Fixed by #17496

Comments

@timfish
Copy link
Contributor

timfish commented Dec 21, 2018

Affects all supported Electron versions and platforms and has been reported and closed before here in 2016.

Expected Behavior
This should not have any side effects:

const { screen } = require('electron');

Actual behavior
However it gives an error:
Error: Cannot require "screen" module before app is ready

As well as the undesired side effects, the error is pretty poor as we're not even requiring the screen module, we're simply accessing the property.

This also means the docs ask developers to do unnecessary complicated things like:

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

app.on('ready', () => {
  let displays = electron.screen.getAllDisplays()

Additional Information
The session API cannot be used before app ready, but can be required without side effects:

// This doesn't result in an error
const { session } = require('electron');

The APIs that are unavailable before app ready should at least behave consistently.

@timfish timfish changed the title require screen moduule before app ready causes error require screen module before app ready causes error Dec 21, 2018
@nornagon
Copy link
Member

nornagon commented Jan 2, 2019

Seems reasonable to me. Looks like the right approach from the code side would be to lazily create an instance of Screen when it's first needed, rather than when the property is accessed. PR welcome!

@sandeep1995
Copy link

Using electron-window-state package throws the same error as above

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

Successfully merging a pull request may close this issue.

3 participants