Issue running a child process using spawn method from an electron app


#1

I am using an electron app to run a child process using spawn method, my code is as given below:

'use strict'
const fixPath = require('fix-path');
let functionName = () => {
    fixPath();           
    const child = childProcess.spawn(process.execPath, [path, ....args], {
      env: {
          ELECTRON_RUN_AS_NODE: 1
      }
});

child.on('error', (err) => {

});

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

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

child.unref();

I am facing this error given below with the above code:

stdout: 
/Users/UserName/Desktop/proj/node_modules/@firebase/firestore/
node_modules/grpc/src/grpc_extension.js:57
throw e;
^Error: 
dlopen(/Users/UserName/Desktop/proj
/name/node_modules/@firebase/firestore/node_modules/grpc/
src/node/extension_binary/node-v57-darwin-x64-unknown/grpc_node.node, 
1): Symbol not found: _GENERAL_NAME_free
Referenced from: 
/Users/UserName/Desktop/proj/
name/node_modules/@firebase/firestore/node_modules/grpc
/src/node/extension_binary/node-v57-darwin-x64-unknown/grpc_node.node
Expected in: flat namespace
in 
/Users/UserName/Desktop/proj/name/node_modules/@firebase/firestore
/node_modules/grpc/src/node/extension_binary/node-v57-darwin-x64-unknown/grpc_node.node
at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:172:20)
at Object.Module._extensions..node (module.js:671:18)
at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:172:20)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (module.js:586:17)
at require (internal/module.js:11:18)
at Object.<anonymous> 
(/Users/UserName/Desktop/proj/name/node_modules/@firebase/firestore/node_modules/
grpc/src/grpc_extension.js:32:13)
at Object.<anonymous> 
(/Users/UserName/Desktop/proj/name/node_modules/@firebase/firestore/
node_modules/grpc/src/grpc_extension.js:63:3)

But when I use ‘exec’ method as shown in the code below it works perfectly fine.

'use strict'
const fixPath = require('fix-path');
let functionName = () => {
    fixPath();           
    const child = childProcess.exec('node ...args', {
      env: {
          ELECTRON_RUN_AS_NODE: 1
      }
});

child.on('error', (err) => {

});

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

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

child.unref();

Why is the error occurring for ‘spawn’ method alone and not for the ‘exec’ method? Anyone on how to resolve this error?