0

I am building a desktop application in which i want to open external application from my app. I'm using electron's child_process for performing this operation. But I'm stuck in how to import child_process on TypeScript file.

I tried to use require('child_process').exec and System.import('child_process').exec but it is throwing error "Can't find module 'child_process'.

But when i use it on index.html in <script> it works properly!

I got this solution here. But it is working with SystemJS. But my project is not configured with SystemJS.

Any help would be appreciated. Thanks in advance!

Shreenil Patel
  • 1,054
  • 1
  • 9
  • 20

1 Answers1

0

I got the solution.

Need to add following array in webpack.config.js.

 externals: [
(function () {
    var IGNORES = ["fs","child_process","electron","path","assert","cluster","crypto","dns","domain","events","http","https","net","os","process","punycode","querystring","readline","repl","stream","string_decoder","tls","tty","dgram","url","util","v8","vm","zlib"];
    return function (context, request, callback) {
        if (IGNORES.indexOf(request) >= 0) {
            return callback(null, "require('" + request + "')");
        }
        return callback();
    };
})()
],

This will tell ionic to ignore modules listed in array IGNORES.

Shreenil Patel
  • 1,054
  • 1
  • 9
  • 20
  • Hello, I'm stuck importing child_process too in an electron + ionic app, but I don't have any webpack.config.js. Somewhere I read that I should use tsconfig.json, but the snippet you post in your solution is not json compliant. Do you have any idea on how to solve that? Should I install webpack in the project? – Appocrypha Sep 30 '19 at 10:58