electron-react-boilerplate: execFile error

I am trying to do is this.

    const execFile = require('child_process').execFile;
    const child = execFile('node', ['./app/scripts/test.js',localStorage['1090']], (error, stdout, stderr) => {
      if (error) {
        throw error;
      }
      console.log('ab aaya  hai');
      //console.log(stdout);
    });
    child.stdout.on('data', (data) => {
      console.log(`${data}`);
    });
    child.stderr.on('data', (data) => {
      console.log(`Error: ${data}`);
    });
    child.on('exit', (code) => {
      console.log(`Child process exit with code ${code}`);
      alert(`Child process exit with code ${code}`);
    });

Works Fine ! In production Build without packaging it works fine too. But doesn’t work after packaging the app. I packaged the the whole application with DEBUG_PROD true. In console it shows this error.

Uncaught Error: Command failed: node ./app/scripts/test.js C:\Users\aksgarg\Desktop\enterprisebusinesscenter module.js:472 throw err; ^

Error: Cannot find module ‘C:\Users\aksgarg\Desktop\JARVIS\release\win-unpacked\app\scripts\test.js’ at Function.Module._resolveFilename (module.js:470:15) at Function.Module._load (module.js:418:25) at Module.runMain (module.js:605:10) at run (bootstrap_node.js:427:7) at startup (bootstrap_node.js:151:9) at bootstrap_node.js:542:3

at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3

at ChildProcess.exithandler (child_process.js:217:12)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:194:7)
at maybeClose (internal/child_process.js:899:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

After packaging the reference to this test.js file is no longer exist.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

Make sure that the file that you are trying to execute is also included in the production build. You can do this by adding it to the files config. Note that this option does not require the file to be processed by webpack or babel. You will have to make sure the worker.js file can be executed without being transpiled.

A better solution is to create a webpack entry point for the worker file. See https://github.com/chentsulin/electron-react-boilerplate/issues/1095 for creating a second entry point. Then make sure that the output of the second entry point is added to the files config. Also make sure that the path to the script is correct in both production and development.