Search code examples
angularsystemjsngrx

"SyntaxError: Unexpected token export(…)"


That's driving me nuts. I am using angular2-quickstart as a starter project. I just added @ngrx/store, @ngrx/core and @ngrx/effects to the project. Now I am getting the error in the title. I don't know how to track the error down as I'm not getting a descriptive error:

(anonymous function)    @   (index):18
ZoneDelegate.invoke @   zone.js:192
Zone.run    @   zone.js:85
(anonymous function)    @   zone.js:451
ZoneDelegate.invokeTask @   zone.js:225
Zone.runTask    @   zone.js:125
drainMicroTaskQueue @   zone.js:357
ZoneTask.invoke @   zone.js:297

Any ideas or references about resolving the cryptic errors SystemJS raises?


Solution

  • My project just ran into the same thing. It would appear that @ngrx/core and @ngrx/store started using ES7 "export" statements in their javascript. These are not supported in any browser right now, and require a transpiler to work.

    So, in order to restore your functionality, the first thing to do is to change your package.json to use an old, working version of @ngrx/*. This is of course not a long term solution, so in the long term, the options are one of the following:

    • Use Babeljs (or similar) to make your compilation chain support ES7.
    • Switch to Webpack and its loaders (as you have done), which are better at reliably outputting code that is standards-compliant. You appear to have done this already.
    • Yell at a ngrx developer about who ever thought it was a good idea to include JS code that is not supported as JS by any browser, without announcing that you now need to do extra work for it.