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

Always return internal module when requiring electron #5662

merged 8 commits into from May 24, 2016


None yet
3 participants

kevinsawicki commented May 23, 2016

We are seeing several reports of errors like TypeError: Cannot read property 'on' of undefined on the object returned from require('electron').app.

This appears to be because people are accidentally (or on purpose) running npm install electron inside their apps which then makes require('electron') return the electron npm module instead of the internal Electron module with all the expected properties.

Then things like the quick start app and other examples will not work since none of the properties are present and the stack trace appears confusing when they open issues.

This pull request patches Module._resolveFilename to always return the internal Electron module when running require('electron'). This seems to be consistent with node's other built-ins like fs, path, etc. that can't be overridden and always return the internal versions when required even when their is a local module by that name in the app's node_modules/ folder.

Here is an example issue: electron/electron-quick-start#53

/cc @electron/maintainers

Closes #3708


This comment has been minimized.


zcbenz commented May 24, 2016


@zcbenz zcbenz merged commit 9d924bb into master May 24, 2016

9 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
electron-linux-arm Build #3288166 succeeded in 39s
electron-linux-ia32 Build #3288167 succeeded in 34s
electron-linux-x64 Build #3288168 succeeded in 112s
electron-mas-x64 Build #1280 succeeded in 5 min 34 sec
electron-osx-x64 Build #1282 succeeded in 6 min 46 sec
electron-win-ia32 Build #287 succeeded in 6 min 5 sec
electron-win-x64 Build #282 succeeded in 6 min 1 sec

@zcbenz zcbenz deleted the electron-require branch May 24, 2016


This comment has been minimized.

BrighTide commented Jul 6, 2016

For anyone else having an off day, this is the error you'll get if you find yourself somehow requiring the main thread in your application

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