0

I have a problem where loading a JavaScript library via CDN works, but serving it from my own server with bower doesn't. The following is a minimal example of what is happening (just a HTML file that can be opened directly):

Loading [email protected] from a CDN

<html>
    <head>
        <script src="https://jspm.io/[email protected]"></script>
    </head>
    <body></body>    
</html>

If I open the Firefox Web Console and enter System, I get:

System
Object { normalize: f/e.normalize(), locate: m/e.locate(), fetch: c/e.fetch(), translate: d/e.translate(), instantiate: d/e.instantiate(), _loader: Object, baseURL: "file:///…", paths: Object, originalSystem: Object, noConflict: $__global.upgradeSystemLoader/p.noConflict(), 17 more… }

Loading [email protected] from a local directory

Then I downloaded the JavaScript file into the same directory as the HTML file and modified it to:

<html>
    <head>
        <script src="[email protected]"></script>
    </head>
    <body></body>    
</html>

If I enter System in the console now, I get:

System
ReferenceError: System is not defined

I should add that window.upgradeSystemLoader is present, which is a function that is defined in the JavsScript library. So at least the file is being detected.


What is the difference? I am trying to serve System.js via bower from my own server, but I always end up in this situation: CDN works, local file doesn't.

7
  • Perhaps browser is prohibiting loading file from local filesystem? Try Chrome's --allow-file-access-from-files flag Commented Aug 11, 2015 at 10:00
  • @DrewR, I also cannot get it to work when I serve it with IIS... Commented Aug 11, 2015 at 10:01
  • @ is a reserved URL character (ref.). So perhaps you have to encode it Commented Aug 11, 2015 at 10:01
  • 3
    I suspect it's treating the @ as part of an attempt to authenticate. When it's buried further along the url as per the CDN, it seems it's ok, but nearer the start it's being parsed as auth info. Commented Aug 11, 2015 at 10:02
  • It also doesn't work if I rename the file to just system.js. I am following the angular 2 quick start from here, btw (scroll down to step 7). Commented Aug 11, 2015 at 10:04

1 Answer 1

2

Something is missing [email protected] i think systemJs helps you load that js file. If you check your console. you would find that that es6-module is missing.

In the system file it requires this src="'+basePath+'[email protected]

You can either download it or change the path in the systemJs source file

You could download it here es6-modules

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.