Skip to content

Can we launch a node command on a mac without node installed when using electron-packager? #1428

@moki298

Description

@moki298
  • Node.js Version: v8.11.3
  • OS: macOS Sierra
  • Scope (install, code, runtime, meta, other?):
  • Module (and version) (if relevant):

I have built a desktop app using electron, and packaged it using electron-packager. The app spawns a child process which uses a 'node' command. My goal is to run the app on a clean mac with no node installed. When I try to launch my app on a clean mac, I am facing "/bin/bash: node not found" error. The electron community said that packaged app does have node bundled into it and it's all about passing right env variables to the child process.

I have been trying to do this and facing various issues, the electron community suggested me to use fork method and when I use 'fork' the child process exits immedately with exit code 1, which as per some documentation is due to some uncaughtexception. So if I am going to use fork I need a way to catch that error. When I use exec method I got stdout.on('data'..) to catch it, Is there similar thing for fork?

Or if I use exec or spawn methods I still get the "node not found" error. So how can I pass proper environment for the child process to run the node command? I should be able to use the node bundled inside packaged app, rather than the node from the mac. Any help is very much appreciated. Thanks.

Something to note, I am using 'fixpath()' to set the $PATH on macOS when run from a GUI app. Not sure if this is messing up something in my code. https://www.npmjs.com/package/fix-path

Please find my code below:

'use strict'
 const fixPath = require('fix-path');

 let func = () => {
   fixPath();   
   const child = childProcess.exec('node /src/index.js --someFlags', {
     detached: true, 
     stdio: 'ignore',
     env: {
       ELECTRON_RUN_AS_NODE: 1,
     }
 });
 child.on('error', (err) => {
   console.log("\n\t\tERROR: spawn failed! (" + err + ")");
 });

 child.stderr.on('data', function(data) {
   console.log('stdout: ' +data);
 });

 child.on('exit', (code, signal) => {
   console.log(code);
   console.log(signal);
 });

 child.unref();
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions