question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
nickdimacommented, Sep 21, 2018

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:

process.chdir(__dirname.replace("/app.asar", ""));
require("ts-node").register();

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 so chdir will break. That’s why we remove app.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.

0reactions
stale[bot]commented, Jun 9, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Electron-forge npm run make "Error: The main entry point to ...
I looked in common.js where the error arose. I tried replacing line 155's if (!(await fs.pathExists(mainScript))) with if (!(await fs.pathExists ...
Read more >
Quick Start | Electron
Run the main process​. The entry point of any Electron application is its main script. This script controls the main process, which runs...
Read more >
electron builder not allowed to load local resource - You.com
I have a small electron app that loads the main.js and main.htm from an /app subfolder. The main.js loads fine and the application...
Read more >
Create a Todo List app with Electron, JavaScript and AG Grid
Full tutorial showing how to use AG Grid in and Electron app to ... The main process acts as an entry point for...
Read more >
A beginner's guide to creating desktop applications using ...
An Electron application's entry point is a JavaScript file (let's call it ... The main process is like a browser and renderer processes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found