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

Add note about non ES6 usage #59

Closed
nick opened this issue Jul 13, 2015 · 20 comments
Closed

Add note about non ES6 usage #59

nick opened this issue Jul 13, 2015 · 20 comments

Comments

@nick
Copy link

nick commented Jul 13, 2015

I initially tried using the following code which didn't work:

var Spring = require('react-motion');
@chenglou
Copy link
Owner

That's because I used webpack's bundling of requires rather than babel's. Your Spring is exposed under require('react-motion').default. If it was babel it'd have automatically added a line to make it work. Related: microsoft/TypeScript#2719

Same problem when you include it as a script tag. A bit annoying. For now the above method works but I'll look into whether webpack can do this too. I use webpack's require because for some reason, if I directly export UMD from babel, webpack doesn't know how to expose a Spring afterward. Maybe a bundling expert can help me with this here.

@chenglou
Copy link
Owner

I'm not explaining this very well lol. @nkbt probably knows this better than I do.

@nkbt
Copy link
Collaborator

nkbt commented Jul 13, 2015 via email

@chenglou
Copy link
Owner

Right, the only reason why I'm even bundling with webpack is for bower support. Thought it was convenient that I can kill two birds with one build. So, if we support bower/script tag, we still need that build, and that's the problem.

@chenglou
Copy link
Owner

#30

@nkbt
Copy link
Collaborator

nkbt commented Jul 13, 2015 via email

@nkbt
Copy link
Collaborator

nkbt commented Jul 13, 2015 via email

@chenglou
Copy link
Owner

I've gradually removed bower support for my other repos. But to be fair, maybe we're a bit in an echo chamber here. Some friends the other day told me they were still using script tags. Dunno about the intersection of people using bower/script tag and those using react-motion

@nkbt
Copy link
Collaborator

nkbt commented Jul 13, 2015

I can fix this stuff
On Jul 14, 2015 8:24 AM, "Nikita Butenko" nik@butenko.me wrote:

I'm surprised to see react ppl using bower

@nkbt
Copy link
Collaborator

nkbt commented Jul 13, 2015 via email

@chenglou
Copy link
Owner

^ I know... that was one of the reasons I didn't want it. Lemme ask on Twitter or something.

@chenglou
Copy link
Owner

Yeah, let's support it, for now...

@gaearon
Copy link
Contributor

gaearon commented Jul 14, 2015

This actually seems correct to me.

react-motion export is an ES6 module, so it has Spring as the default export, and some other named exports. It's not a bug or a mistake—it's just the way ES6 exports work.

If you don't want that behavior, you can go back to using module.exports = Spring, but then you'd have to change other named exports to be statics on Spring.

Not a Webpack issue, is it?

@gaearon
Copy link
Contributor

gaearon commented Jul 14, 2015

Even Babel can't “make it work” on the export side.

Babel does “interop import” on the import side: if you import an ES5-style module from Babel, it will “pretend” it has a default export.

But it can't turn an ES6 module into something consumable by ES5 code without .default because that's just the spec.

@chenglou
Copy link
Owner

It's not a mistake, but Babel goes a step further and does

exports["default"] = test;
module.exports = exports["default"];

After which you can use var Spring = require('react-motion') directly.

You know what, maybe there shouldn't be a default export for this library?

@gaearon
Copy link
Contributor

gaearon commented Jul 14, 2015

Oh, you're right.
But let's make Spring named export then? Problem solved :-)

@chenglou
Copy link
Owner

We can have the excuse that I might expose a Decay component, heh

@gaearon
Copy link
Contributor

gaearon commented Jul 14, 2015

After all it's not just one component..
And people can write

import { Spring } from 'react-motion'

and

var Spring = require('react-motion').Spring

and everyone's happy

@gaearon
Copy link
Contributor

gaearon commented Jul 14, 2015

You already have a TransitionSpring so it's fair deal now I think

@nkbt
Copy link
Collaborator

nkbt commented Jul 18, 2015

Okay, the mystery of the Century revealed. This is why people still use bower - Rails! Going to explore some ways to support bower without checking in pre-built code into a repo.

I'll make a PR if I come up with some reasonably good solution.

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

4 participants