3

I have an angular2 webpack project that is running in electron. I'm trying to use shelljs but webpack fails to build with the error:

[0] ERROR in ./~/shelljs/src/exec.js
[0] Module not found: Error: Can't resolve 'child_process' in 'D:\Projects\angular-electron\node_modules\shelljs\src'
[0]  @ ./~/shelljs/src/exec.js 6:12-36
[0]  @ ./~/shelljs/src ^\.\/.*$
[0]  @ ./~/shelljs/shell.js

My webpack configuration is targeting the electron-renderer and my polyfills are using zone-node:

return { 
    target: 'electron-renderer', //webpack-build-common.js
    ...

and

import 'zone.js/dist/zone-node'; //polyfills.ts

I have tried changing the webpack target to node but it has no effect.

You can see my entire webpack configuration on paste bin

otoomey
  • 939
  • 1
  • 14
  • 31
  • A bit late for you, but this seems to be similar - https://stackoverflow.com/questions/44305603/types-node-installed-typescript-version-not-able-find-module-child-process – JsAndDotNet Nov 08 '17 at 15:37
  • I wonder if editing `package.json` is the answer: https://stackoverflow.com/a/54459622/470749 – Ryan Jul 17 '20 at 22:11

1 Answers1

0

Choose call exec into main.ts electron in ipcrender, work fine example:

ipcMain.on('ipc-callchild', async (event, arg) => {
  const child = require('child_process').execFile;
  const executablePath = "C:\\Program Files (x86)\\browser.exe ";
  let parameters = [`${arg}`, "--kiosk", "--private-window"];
  child(executablePath, parameters, function(err, data) {
  console.log(err)
  console.log(data.toString());
  });
});