bubenshchykov / ngrok

Expose your localhost to the web. Node wrapper for ngrok.
https://ngrok.com
2.33k stars 317 forks source link

Not work in Electron production. #297

Closed imyuanx closed 1 year ago

imyuanx commented 1 year ago

Hey, I have a electron app, I got an error after building. It is normal in development mode.

ngrok binary file is packed into asar archive, so call ngrok must use execFile. (Description in electron)

I solved the problem by hack:

// In '/node_modules/ngrok/src/process.js' 2 line
const { execFile, exec: execCallback } = require("child_process");
const spawn = execFile;

Maybe we can provide an option for electron?

philnash commented 1 year ago

I don't think you can pack the binary into the package, as different ngrok binaries run on different operating systems. If you are building and testing your electron based application on one operating system, you will find that it works, but if you were to try your application on a different operating system you'd probably find that the packaged ngrok binary would fail.

That's why this package downloads the correct ngrok binary for the system it is installed on as its first job.

Since you are packaging the application, you may need to call upon the download function as described here to fetch the correct binary for the system the application is running on.

imyuanx commented 1 year ago

It is difficult to package applications for other operating systems, so we need to package applications for the current system on each operating system.

Downloading the ngrok binary file after the build will have some requirements for the network, But this can reduce the volume of the application.

This may require some trade-offs.

philnash commented 1 year ago

I understand that's not ideal. The good news is that ngrok themselves are starting to build out the agent functionality as libraries. They have a go-lang version and a rust version so far. So in the future you should be able to require the JavaScript version of the ngrok agent to handle this. It's worth looking out for in the future.

imyuanx commented 1 year ago

OK, So far, this package is the best solution, Thank for you great job!