These are chat archives for systemjs/systemjs

18th
Mar 2016
BoeseB
@BoeseB
Mar 18 2016 08:13
how to use the Node require method to resolve a require call? I need to load a nodemodule called 'remote' from electron-prebuilt. If i load it in javascript with var remote = require('remote') i get the right instance, but as soon as i use Typescript this code is put inside a define(["require", "exports"], function(require, exports){...} block so the require got overwritten. And the require call fails. How can i avoid this or tell systemjs to resolve the "remote" module with the node require method? see Gist for example code
Manuel Pacheco
@ShadowManu
Mar 18 2016 08:22
try using the module compiler option to commonjs. Even more, I recommend using the ES6 import style --> import * as remote from 'remote';
BoeseB
@BoeseB
Mar 18 2016 08:22
@ShadowManu thanks, is there a guide how to use this?
the option i mean
Manuel Pacheco
@ShadowManu
Mar 18 2016 08:23
if you're using a tsconfig.json file --> https://github.com/Microsoft/TypeScript/wiki/tsconfig.json
or if using the compiler cli options --> https://github.com/Microsoft/TypeScript/wiki/Compiler-Options
BoeseB
@BoeseB
Mar 18 2016 08:25
ok amd and commonjs won't do the trick i get the error "Failed to load resource: net::ERR_FILE_NOT_FOUND
aurelia-logging-console.js:62 ERROR [app-router] Error: XHR error loading file:///D:/Development/aurelia_test/dist/remote.js(…)error @ aurelia-logging-console.js:62"
so i guess i need to configure some map for systemjs to resolve it with nodes require method
but i dont know how
Manuel Pacheco
@ShadowManu
Mar 18 2016 08:26
just to understand: you're using systemjs for a browser environment, right?
BoeseB
@BoeseB
Mar 18 2016 08:26
yes
or no i use electron shell
Manuel Pacheco
@ShadowManu
Mar 18 2016 08:26
any link to that?
BoeseB
@BoeseB
Mar 18 2016 08:27
Manuel Pacheco
@ShadowManu
Mar 18 2016 08:32
I'm not that sure of what kind of project you're doing, but I may throw an arrow and see if it hits: in the FAQ of Electron it is mentioned a possible conflict over module, exports and require (just like SystemJS may need). Have you taken that into account?
BoeseB
@BoeseB
Mar 18 2016 08:37
Either i don't get it or this isn't the problem in this case. If i run a JavaScript file where i pull the require call outside of the define(..) of the transpiled TypeScript code it works all fine. So in my opinion the module loader needs to be configured the right way
to resolve the 'remote' import with the right loader
Manuel Pacheco
@ShadowManu
Mar 18 2016 08:45

look at the output of the first option I gave you: --module commonjs and using ES6. I just did an the output ends being:

var remote = require('remote');
var EdgeTest = (function () {
    function EdgeTest() {
        this.edge = remote.require('electron-edge');
        this.myInput = 'TypeScript';
        this.myResult = '';
        this.helloWorld = this.edge.func("async (input) => { return \".NET Welcomes \" + input.ToString();}");
    }
    EdgeTest.prototype.submit = function () {
        this.helloWorld(this.myInput, function (error, result) {
            if (error)
                throw error;
            this.myResult = result;
        });
    };
    return EdgeTest;
})();
exports.EdgeTest = EdgeTest;

Which should work, shouldn't it?

BoeseB
@BoeseB
Mar 18 2016 08:48
i dont know how this file is loaded with commonjs but the require call is already overwritten in the common module
In amd this is working
Manuel Pacheco
@ShadowManu
Mar 18 2016 08:49
I really don't get your environment: node or browser? and if node, why systemjs?
BoeseB
@BoeseB
Mar 18 2016 08:50
var remote = require('remote'); 
define(["require", "exports"], function (require, exports) {
    "use strict";
    var EdgeTest = (function () {
        function EdgeTest() {
            this.edge = remote.require('electron-edge');
            this.myInput = 'TypeScript';
            this.myResult = '';
            this.helloWorld = this.edge.func("async (input) => { return \".NET Welcomes \" + input.ToString();}");
        }
        EdgeTest.prototype.submit = function () {
            this.helloWorld(this.myInput, function (error, result) {
                if (error)
                    throw error;
                this.myResult = result;
            });
        };
        return EdgeTest;
    }());
    exports.EdgeTest = EdgeTest;
});
My App is a standard template using Aurelia similar framework to angularJS. This template already uses systemJS
Manuel Pacheco
@ShadowManu
Mar 18 2016 08:53
can I get a link to the template?
BoeseB
@BoeseB
Mar 18 2016 08:54
And runs fine under edge, but now i want to also use Edge] to call C# code from javascript. This only works in the main process of the electron shell, so i need the electron "remote" module to load the edge library in the main process
BoeseB
@BoeseB
Mar 18 2016 11:22
@guybedford ist there a way to override the normalization in a loader plugin? I want the require('remote') call to be redirected to System._nodeRequire('remote'), but all i get in the plugin is the already resolved name to a full path like System._nodeRequire('c:\\myapp\\somedir\\remote.js') but the module is in a directory of the node installation so i want to rely on nodes own normalization/lookup logic. Or is it possible to directly tell SystemJS to redirect import remote from 'remote'; to a call to System._nodeRequire('remote') without a loader plugin? I can't call System_nodeRequire directly cause it's not defined in my usercode, but in a loader plugin it is.
Manuel Schweigert
@Manuel-S
Mar 18 2016 12:45
Hey there
is there a way to hook into system.js just before the ajax requests are sent?
I would like to append stuff to the urls for caching purposes
pantonis
@pantonis
Mar 18 2016 16:49
Im totally newbie in web programming
any good tutorial that I can read about what systemjs is because apparently is widely used?
searched in google but too many unuseful links
Manuel Pacheco
@ShadowManu
Mar 18 2016 18:00
@pantonis I believe that the core feature is SystemJS is being a loader. ES5 doesn't have any kind of real import right? (Just script tags everywhere in HTML). Well, there you go, something helping you to load stuff and including the different non-official loading styles that the community has done (CommonJS, AMD, UMD and now ES6). There are other things like loading non-js stuff (css, webfonts, etc) and packaging (building) for production too.
pantonis
@pantonis
Mar 18 2016 18:00
@ShadowManu thanks a lot