I have my packaged electron app using electron-packager and I want to run this app in any mac which doesn't have node installed. I was suggested that electron-packager bundles the node into my app, but when I try launching it on a mac I get the 'node command not found error'.
I get this because I invoke a child process in my application that executes a node command to run a script. In electron slack, I was suggested to run my electron process as plain node process by setting the environment variable ELECTRON_RUN_AS_NODE. I cannot figure out where and how I can set this, any idea on how to do this? Also, is this going to solve the issue?
One can use 'fork' method to run a node process and this even works on a machine with no node installed. 'Fork' method uses the executable path of the parent process in this case electron app. The sample code for fork method is given below:
const child = childProcess.fork(path, args, {
silent: true,
detached: true,
// stdio: 'ignore',
env: {
ELECTRON_RUN_AS_NODE:1
}
});
Also set the 'ELECTRON_RUN_AS_NODE' env variable. This worked for me and I was able to run the app on a mac with no node installed.
Alright, so your problem is this: Electron packages nodeJS to work only within the scope of that application. When spawning additional processes you are telling the OS that it must use "node" installed on the OS, not the node bundled with electron. So, if node is not installed on that system, you cannot call node to run a script.
go have a look at the pkg module. What is does, is take a script and bundles node into an executable and then you can refer to that when spawning a process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With