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.

Does not work in Electron on Windows

See original GitHub issue

Despite my best efforts, I cannot get this to work in Electron. The program always fails and shows an error window indicating a C/C++ error, not even a JS error:

image

My steps:

  1. Create an empty Node.js project.
  2. Install electron, tdl, and electron-rebuild.
  3. Run npx electron-rebuild to retarget the native bindings to Electron.
  4. Download the precompiled Telegram binaries and put them in a lib folder.
  5. Create index.js with the following code:
const { Client: TGClient } = require("tdl");

(async () => {
    console.log("initialising tg client");

    try {
        const tgClient = new TGClient({
            apiId: 000000,
            apiHash: "oops",
            binaryPath: "lib/tdjson",
            useTestDc: true,
            useMutableRename: true,
            verbosityLevel: 10
        });

        console.log("initialised tg client");

        await tgClient.connect();

        console.log("connected tg client");

        tgClient.on("update", (...args) => console.log("tg client: ", ...args));
        tgClient.on("error", (...args) => console.error("tg client: ", ...args));

    } catch (e) {
        console.error(e);
    }
})();
  1. Run npx electron . to launch the program.
  2. Program prints “initialised tg client”, indicating that tdl successfully loads, but then crashes as soon as I call connect().
  3. Get confronted with this inscrutable error window.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Banneretscommented, Oct 27, 2018

Confirm that it fails on Windows.


It seems that it works with ffi instead of ffi-napi. Try this:

npm i https://github.com/node-ffi/node-ffi.git#169773db0d56c4c99225b307b3dc86a46f3af34d
npm i ref
npx electron-rebuild

then replace require('ffi-napi') with require('ffi') and require('ref-napi') with require('ref') in node_modules/tdl/dist/tdlib-ffi.js file.


After some debugging I found that it crashes due to async ffi calls. Minimal reproducible example:

const ffi = require('ffi-napi')
//const ref = require('ref-napi')
console.log(0)
const kernel32 = ffi.Library('kernel32', {
  Sleep: ['void', ['int32']]
})
console.log(1)
kernel32.Sleep.async(1000, err => console.log('err', err))

( kernel32 here is just for example, you can use any function. Example from tdl: )

const ffi = require('ffi-napi')
const tdjson = ffi.Library('tdjson', {
  'td_json_client_create': ['pointer', []]
})
tdjson.td_json_client_create.async((err, cl) => {
  if (err) console.log('Error', err)
  else console.log('Client created', cl)
})

I think we should open an issue somewhere in nodejs / electron / node-ffi-napi repo.


Versions:

  • Windows 10
  • electron: v3.0.6 (uses node v10.2.0)
  • electron-rebuild: v1.8.2
  • ffi-napi: v2.4.3
  • ref-napi: v1.4.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

electron quick start application not working - Stack Overflow
I have to run electron index.html to resolve this issue.
Read more >
Any Electron app running on Win 10 16299.19 are not rendered
Electron version: Dont know which electron version is used by apps. I tiried latest Slack, Discord(Including PTB and Canary versions) and ...
Read more >
Electron App does not open after following Windows building ...
HELP: Electron App does not open after following Windows building Instructions. directory, i get some weird errors. i have node-gyp installed ...
Read more >
Build Instructions (Windows) - Electron
Building Electron is done entirely with command-line scripts and cannot be done with Visual Studio.
Read more >
Common Configuration - electron-builder
If you want to use js file, do not name it electron-builder.js . It will conflict with electron-builder package name. Tip. If you...
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