systemjs / builder

SystemJS build tool
MIT License
465 stars 122 forks source link

Plugin/Module not registered correctly after transpiling to ES5 #844

Open xwisdom opened 6 years ago

xwisdom commented 6 years ago

Hello,

I'm getting the following error in the browser after loading code generated by the builder:

Error: Module instantiation did not call an anonymous or correctly named System.register.
  Instantiating http://127.0.0.1:81/path/to/data!pluginx

Here's the Javascript code and SystemJS configuration:

import myData from 'path/to/data!pluginx';

console.log(myData)
SystemJs.config({
    map: {
        pluginx: 'assets/scripts/pluginx.js'
    }
})

The builder generates the following output:

System.registerDynamic('path/to/data!assets/scripts/pluginx.js', ['lib/dataconverter.js'], false, function ($__require, $__exports, $__module) {
  return (function (obj) {
    return obj.convertData('path/to/data');
  }).call(this, $__require('lib/dataconverter.js'));
});

System.register('app/modules/main.js', ['path/to/data!pluginx'], function (_export, _context) {
  "use strict";

  var myData;
  return {
    setters: [function (_pathToDataPluginx) {
      myData = _pathToDataPluginx.default;
    }],
    execute: function () {

      console.log;

    }
  };
});

I think SystemJS is trying to load "path/to/data!pluginx" from the server because it not registered.

If I change System.registerDynamic('path/to/data!assets/scripts/pluginx.js',...) to System.registerDynamic('path/to/data!pluginx.js',...) then it works just fine.

Why is the builder generating code to register path/to/data!assets/scripts/pluginx.js instead of path/to/data!pluginx? Is this a bug?