Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 library interpreted as CJS when installed #1075

Closed
nateabele opened this issue Aug 29, 2015 · 3 comments
Closed

ES6 library interpreted as CJS when installed #1075

nateabele opened this issue Aug 29, 2015 · 3 comments

Comments

@nateabele
Copy link

Okay, first of all, it's time to come clean @guybedford: you're not a real person, are you? You're either multiple people, or some kind of Open Source project AI robot (or both?). Either way, it's time to tell the public the truth. This deception is making the rest of us look bad.

😉

With that out of the way...

When I install this project via jspm install npm:geometry.js, and then attempt to do jspm bundle-sfx, I get the following error (formatted for your viewing pleasure):

file:///<trimmed>/jspm_packages/npm/geometry.js@0.1.1/Point.js:3:1:
  Unexpected reserved word export,
file:///<trimmed>/jspm_packages/npm/geometry.js@0.1.1/Point.js:3:8:
  Semi-colon expected,
file:///<trimmed>/jspm_packages/npm/geometry.js@0.1.1/Point.js:3:8:
  Unexpected reserved word default,
file:///<trimmed>/jspm_packages/npm/geometry.js@0.1.1/Point.js:3:16:
  Semi-colon expected,
file:///<trimmed>/jspm_packages/npm/geometry.js@0.1.1/Point.js:5:17:
  Unexpected token :...

This seems to be because this:

/* */ 
"format cjs";

...gets prepended to all the source files. If I change cjs to es6, bundling works without error.

What's causing it to get interpreted as CJS?

@guybedford
Copy link
Member

Haha, feeling rather slow this week, so glad to hear my AI is suitably deceiving :)

When installing packages from npm, we only follow the exact same rules you would get if you published a package to npm and loaded it in Node. That is we only support loading as CommonJS currently. If we set up ES6 semantics for npm, that would be creating our own convention, different to how npm may decide to implement ES6 in future.

To manually alter this with an override there are a few options mentioned in https://github.com/jspm/jspm-cli/wiki/Publishing-Packages#publishing-jspm-style-packages-to-npm, you can set a custom format via an override with jspm install npm:geometry -o "{format:'esm'}".

@nateabele
Copy link
Author

That sounds like it should work, thanks a lot.

Also, does that mean that installing from GitHub uses package format auto-detect semantics?

@guybedford
Copy link
Member

Yes exactly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants