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.