HTTP 404 from unpkg when using SystemJS

293 views Asked by At

I am currently using SystemJS to dynamically import custom modules at runtime as part of a plugin system. I have succeeded in the initial import, however, my approach quickly fails when trying to import dependency packages from https://unpkg.com/.

I have uploaded a simple, isolated sample to Plnkr to demonstrate my issue, in the hopes that someone will be able to help me figure out the cause and a subsequent solution.

SystemJS.config({
  paths: {
    'npm:': 'https://unpkg.com/'
  },
  map: {
    'rxjs': 'npm:rxjs'
  }
});

SystemJS.import('rxjs')
  .then(function () {
      console.log('rxjs has been loaded');
  })
  .catch(function (error) {
      console.error(error);
  });

When running, if you look in the console output or network tracing (I have also written some of the output to the web page), you will see a series of GET requests to the unpkg server to download packages that I assume are required by rxjs (the package I'm trying to import in my example to demonstrate the issue). I have tried re-mapping the internal libraries that it depends upon to a different URL that does not return 404, but that does not seem to have any effect. I have also tried manually browsing to the paths in the console output, and I can see that unpkg does indeed fail to find them. So I am guessing there is a mismatch somewhere with the dependency referencing triggered within SystemJS and the paths unpkg offers.

I am new to SystemJS, so it may simply be a misunderstanding on my part. Any help would be appreciated.

1

There are 1 answers

0
Denys Vuika On

You can try binding it directly to the index file:

{ map: { 'rxjs': 'npm:rxjs/index', 'rxjs/*': 'npm:rxjs' } }

Worked for me with your Plunkr example.