Search code examples
javascriptecmascript-6systemjsjspmes6-module-loader

Can't import bundled file


I'm doing this in my application

System.import('lib/bootstrap.js').then(m => {
   this.socket = m.io("http://localhost:3000");
})

This is bootstrap.js

import io from 'socket.io-client';
export { io };

I created a bundle via jspm bundle lib/bootstrap.js outfile.js.

When I try to System.import('outfile.js') the resolved Promise m is only an empty Object. What am I doing wrong here?

System.import('outfile.js').then(m => {
   this.socket = m.io("http://localhost:3000");
})

Solution

  • You don't want to import the bundled file. What you need to do is inject the bundle configuration to your config.js file. For example adding jspm bundle lib/bootstrap bootstrap-bundle.js --inject will add

    "bundles": {
        "bootstrap-bundle": [
        "socket.io-client.js",
        "lib/bootstrap.js"
      ]
    }
    

    to your config.js file. Then you just need to import your file as usual:

    System.import('lib/bootstrap.js').then(m => {
       this.socket = m.io("http://localhost:3000");
    })
    

    See the documentation here.