martyjs / marty

A Javascript library for state management in React applications
http://martyjs.org
MIT License
1.09k stars 76 forks source link

Error Importing Marty with JSPM / System.js / ES6 #277

Closed pvormittag closed 9 years ago

pvormittag commented 9 years ago

I'm attempting to use Marty on a large web app build, which uses JSPM / System.js for module loading. JSPM has no problem installing Marty, but System.js fails when attempting to import Marty.

A test case is creating a simple app/module.js file and attempting to import Marty within the module.

// Only statement in app/module.js
import Marty from 'marty';

Then making a simple html file:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Test</title>
</head>
<body>
  <script src="jspm_packages/system.js"></script>
  <script src="system.config.js"></script>
  <script type="text/javascript">
    System.import('app/module');
  </script>
</body>
</html>

The StackTrace output from Chrome is then:

Uncaught SyntaxError: Unexpected token (
system.src.js:2255 Uncaught Error evaluating http://localhost:8080/vendor/npm/marty@0.9.9/lib/instances.js
Uncaught SyntaxError: Unexpected token (
system.src.js:2255 Uncaught Error evaluating http://localhost:8080/vendor/npm/marty@0.9.9/lib/state.js
Uncaught Error evaluating http://localhost:8080/vendor/npm/marty@0.9.9/lib/instances.js
Uncaught SyntaxError: Unexpected token (
es6-module-loader.src.js:140 Potentially unhandled rejection [2] Error loading "npm:marty@0.9.9/marty" at http://localhost:8080/vendor/npm/marty@0.9.9/marty.js
Error loading "npm:marty@0.9.9/marty" from "app/main.js!github:floatdrop/plugin-jsx@1.1.0" at http://localhost:8080/app/main.js
Error evaluating http://localhost:8080/vendor/npm/marty@0.9.9/marty.js
Uncaught Error evaluating http://localhost:8080/vendor/npm/marty@0.9.9/lib/state.js
Uncaught Error evaluating http://localhost:8080/vendor/npm/marty@0.9.9/lib/instances.js
Uncaught SyntaxError: Unexpected token ( (WARNING: non-Error used)

I'm unsure if this issue is caused by Marty mixing syntax between CommonJS and ES6, or if es6-module-loader or System.js is not correctly handling a valid use case. I have JSPM configured to use Babel for ES6 transpiling and the system loads react and react-router without any issue.

jhollingworth commented 9 years ago

One thing to try, can you edit http://localhost:8080/vendor/npm/marty/package.json#main to point to "dist/node/marty.js"?

jhollingworth commented 9 years ago

Hey, I'm going to close this for now. Please re-open if you feel my comment hasn't fully answered your question