I'm writing a Mac OSX GUI with Electron and Nativefier package and when i run the packaged app on a machine with Nodejs installed (globally), everything works fine.
On a machine without Nodejs installed the command can't be found.
I'm using the Nativefier Cli inside Electron with a full path to cli:
var cliCmd = '"'+app.getAppPath()+'/node_modules/nativefier/lib/cli.js"';
const child_process = require('child_process');
child_process.exec(cliCmd+' --name "App Name" "http://appname.tld" --platform darwin --arch x64 --electron-version "0.36.6"', function (error, stdout, stderr) {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
I'm getting this error: "env: node: No such file or directory"
Checked the app.getAppPath() dir and it's correct.
Also, i tried to pass the env and cwd parameters, but without any success.
child_process.exec(cliCmd+' --name "App Name" "http://appname.tld" --platform darwin --arch x64 --electron-version "0.36.6"',
{
env: {"ATOM_SHELL_INTERNAL_RUN_AS_NODE":"1"},
cwd: app.getAppPath()
},
function (error, stdout, stderr) {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
What i'm doing wrong? I tried child_process.spawn() also, but without any luck again.
What i need to do to call a packaged node_module/cli from my app, on a machine without nodejs installed?
I found execPath inside the process object
and now i can execute nodejs commands on a machine without nodejs installed globally. It's using the Electron's built-in version.
child_process.exec(process.execPath+' '+cliCmd+' --name "App Name" "http://appname.tld" --platform darwin --arch x64 --electron-version "0.36.6"',
{
env: {"ATOM_SHELL_INTERNAL_RUN_AS_NODE":"1"},
cwd: app.getAppPath()
},
function (error, stdout, stderr) {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
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