Ced Ced - 2 years ago 346
Javascript Question

Importing node modules with electron and Systemjs

I just wondered if it is possible to make systemjs use require("remote").require("nodemodule"), if system js can't find the module in its own registry?

I think something like this mechanism is already working when using electron with typescript and commonjs modules...

Has someone already solved that struggle?

Ced Ced
Answer Source

Finally after some time I found a working solution:

var node_modules = ["child_process","fs"];
var fetch = System.fetch;
System.fetch = function () {
    var promise= fetch.apply(System,arguments);
    return promise.then(function (js) {
        for(var m of node_modules){
            var requireExpression = 'require("'+m+'");';
            var remoteRequire = 'remote.require("'+m+'");'
        return js;

Just add all imported node_modules to the array and things are fine

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download