google / traceur-compiler

Traceur is a JavaScript.next-to-JavaScript-of-today compiler
Apache License 2.0
8.17k stars 580 forks source link

import fails in browser #2059

Open davie opened 8 years ago

davie commented 8 years ago

We've been using traceur (on the fly in browser) for a while, but a recent change seems to have stopped modules being imported. We're doing the same as the example on https://github.com/google/traceur-compiler/wiki/Getting-Started#a-touch-of-class

<script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
<script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>
<script type="module">
  import "myModule.js";
</script>

importing a module now fails with the following error:

ReferenceError: System is not defined
    at BrowserTraceurLoader.$__super.normalize (http://google.github.io/traceur-compiler/bin/traceur.js:32280:48)
    at InternalLoader.getOrCreateCodeUnit_ (http://google.github.io/traceur-compiler/bin/traceur.js:31942:43)
    at http://google.github.io/traceur-compiler/bin/traceur.js:32000:26
    at Array.map (native)
    at InternalLoader.handleCodeUnitLoaded (http://google.github.io/traceur-compiler/bin/traceur.js:31999:52)
    at InternalLoader.module (http://google.github.io/traceur-compiler/bin/traceur.js:31904:14)
    at BrowserTraceurLoader.Loader.module (http://google.github.io/traceur-compiler/bin/traceur.js:32163:37)
    at WebPageTranscoder.addFileFromScriptElement (http://google.github.io/traceur-compiler/bin/traceur.js:32534:39)
    at WebPageTranscoder.addFilesFromScriptElements (http://google.github.io/traceur-compiler/bin/traceur.js:32557:18)
    at WebPageTranscoder.selectAndProcessScripts (http://google.github.io/traceur-compiler/bin/traceur.js:32592:14)

It looks like we also need to include BrowserSystem for this to import successfully.

<script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
<script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>
<script src="https://google.github.io/traceur-compiler/bin/BrowserSystem.js"/>

Is this intentional, and if so does the wiki just need updating?

johnjbarton commented 8 years ago

Yes this was intended and yes the wiki needs to be updated. Will you be able to do that?

I'm working on browser-based testing to prevent this from happening yet again.

davie commented 8 years ago

OK, thanks - I've updated that page now.

arv commented 8 years ago

Why don't we include BrowserSystem in bootstrap.js?