Issue when using ts-node/register in the main entry point of Electron
See original GitHub issue- Version: 20.15.1
- Target: macOS as of right now
My current main entry point for the electron-main process is just the following two lines
require("ts-node").register();
require("./ElectronMain");
while the ElectronMain.ts
is generically creating and displaying the main window. When running electron .
locally it works fine but after running electron-builder
the app does not work. On macOS the icon bounces in the dock and nothing happens until I Force Quit the app. I tracked the issue down to the inclusion of ts-node
. Basically the package electron app that the builder produces never passes the require("ts-node").register()
statement. The ts-node
package seems to be included correctly into the app archive and I can just assume that either it is not loaded at all but does not error or hangs during the execution of the register
function.
My current workaround is to add a second build step and transpile the ElectronMain.ts
into corresponding Javascript and it works. So it is literally just ts-node
that doesn’t get loaded/executed properly in the packaged electron application while it works when just running electron .
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
I manage to find a solution for MacOS. It seems that changing the working dir for the node process to the app’s dir before registering
ts-node
fixes this, but I’m not sure why. So what you need to do is this:If you don’t use asar you can remove the
replace
function call, but leaving it shouldn’t hurt anyway. The problem with asar is that when inside an asar package__dirname
’s value will not be an actual dir sochdir
will break. That’s why we removeapp.asar
from the path. In your case the package name could be something else so try to log__dirname
and see exactly how the asar package is called.Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.