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
importing powerMonitor from electron before 'ready' event causes crash #21716
Comments
Why can't you just use
Also, does electron support TypeScript natively? If so, please specify URL that discusses this. As much as I like TS, keeping reproduction code as simple as possible is desirable, so I would've preferred it to be written directly in JS.
I suspect that to be due to "luck". When you use something in a way that is forbidden by the specs you should expect undefined behavior. |
Can confirm the issue is reproducible. Although TypeScript developers normally do (no import-start helper involved in both cases)
or
instead of
Besides, in a real-world scenario, you would probably go with Webpack/Rollup/etc bundlers which often have own module loading wrappers that usually do |
Sure, but is it a bug in electron? It looked to me like this only happens when the application code attempts to load the
Exactly. That is what is causing the problem in your code. electron/shell/browser/api/atom_api_power_monitor.cc Lines 106 to 116 in 0fe6767
|
In my opinion, loading the library and using it are different things. So from this point that would be a bug in Electron. But it's clear the Electron initializes the instance eagerly/on-module-loading electron/lib/browser/api/power-monitor.ts Line 11 in ec61041
So maybe it's just documentation issue and the docs should be adjusted like you can't Given the import start helper code: var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
}; The power monitor module and all of them listed on And well, it's better not to use TS import-start stuff a lot since if affects performance, you know that |
Actually I think Electron could do something like:
Though if for the instance Instead of eagerly calling electron/lib/browser/api/power-monitor.ts Lines 14 to 26 in ec61041
|
Yeah, I agree this is a bug in Electron rather than an issue with ts wildstar. For example, you can remove typescript from the equation altogether and instead try to run the sample code from the top of
That code causes the same failure on If you don't mind, I'm going to edit the issue topic to reflect that the issue doesn't require TypeScript |
powerMonitor can't be used until the app is ready; however, on Linux, powerMonitor.on() was called as soon as lib/browser/api/power-monitor.ts was loaded. This patch takes @vladimiry's suggestion of wrapping that in an app.on('ready') handler to prevent powerMonitor.on() from being called prematurely. Fixes #21716
* fix: use powerMonitor.on() only after app is ready powerMonitor can't be used until the app is ready; however, on Linux, powerMonitor.on() was called as soon as lib/browser/api/power-monitor.ts was loaded. This patch takes @vladimiry's suggestion of wrapping that in an app.on('ready') handler to prevent powerMonitor.on() from being called prematurely. Fixes #21716
powerMonitor can't be used until the app is ready; however, on Linux, powerMonitor.on() was called as soon as lib/browser/api/power-monitor.ts was loaded. This patch takes @vladimiry's suggestion of wrapping that in an app.on('ready') handler to prevent powerMonitor.on() from being called prematurely. Fixes #21716
powerMonitor can't be used until the app is ready; however, on Linux, powerMonitor.on() was called as soon as lib/browser/api/power-monitor.ts was loaded. This patch takes @vladimiry's suggestion of wrapping that in an app.on('ready') handler to prevent powerMonitor.on() from being called prematurely. Fixes #21716
* fix: use powerMonitor.on() only after app is ready powerMonitor can't be used until the app is ready; however, on Linux, powerMonitor.on() was called as soon as lib/browser/api/power-monitor.ts was loaded. This patch takes @vladimiry's suggestion of wrapping that in an app.on('ready') handler to prevent powerMonitor.on() from being called prematurely. Fixes #21716 * refactor: handle import powerMonitor timing issue Fix the previous commit's app-is-ready handler by checking to see if app is already ready when power-monitor.ts is loaded. * refactor: use app.whenReady() for simpler logic * chore: use a consistent comment formatting style Co-authored-by: Charles Kerr <ckerr@github.com>
Preflight Checklist
Issue Details
Same as #18966, app crashed when launched.
Here is my repro sample.
https://github.com/mtgto/sample-electron-crash
Here is compiled index.ts
https://gist.github.com/mtgto/2a60ed4ce2e280c7577412884cde166e
Expected Behavior
Open an empty window.
Actual Behavior
To Reproduce
Screenshots
N/A
Additional Information
Stacktrace says
__importStar
calls powerMonitor. It happens when tsconfig usesesModuleInterop: true
(default is true)In macOS, app doesn't crash.
The text was updated successfully, but these errors were encountered: