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

[Packager] ES6 Modules feature #1480

Closed
alinz opened this issue Jun 1, 2015 · 13 comments
Closed

[Packager] ES6 Modules feature #1480

alinz opened this issue Jun 1, 2015 · 13 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@alinz
Copy link

alinz commented Jun 1, 2015

One of the feature that I really want to have is the new module syntax in es6. By brining Babeljs into the eco system I thought I can use it. Unfortunately, es6.modules are not part of the whitelist :(

To me es6 module removes a lot of code and makes the code more readable and clean.

Any thoughts on this?

p.s. I know module feature is not ready yet, but the whole point of using Babel is to use the next generation syntax safely. Well, I hope I my assumption is right. :D

@brentvatne brentvatne changed the title ES6 Modules feature [Packager] ES6 Modules feature Jun 1, 2015
@jtremback
Copy link
Contributor

More detail: #1451

I'm going to just use browserify + babelify before sending files to the packager to get around these issues. I'll post an example in an hour or so.

EDIT: This doesn't work.

@euforic
Copy link

euforic commented Jun 2, 2015

@jtremback you can just use the babel cli tool directly to pre-compile, but being able to do this directly in the react-native packager would be much nicer.

Below is an example script I added to my package json to do this.

$ ./node_modules/.bin/babel ./src/ --out-dir ./lib/ --stage 0 --ignore '/node_modules/' --optional runtime --watch &

Then just make your index.ios.js like this:

require('./lib');

One thing to note: Sometimes the react packager runs after the babel compile so you need to save twice to see your changes.

@alinz
Copy link
Author

alinz commented Jun 2, 2015

@euforic I rather modify packager/transformer.js and add 'es6.modules' into the whitelist than go through all these hacks. I wish we could override the whitelist with .babelrc. crossing finger to see this feature soon.

@jtremback any news on your side? Do you think we might be able to override whitelist with .babelrc file?

@jtremback
Copy link
Contributor

@euforic I tried that, had some other issues, specifically around Babel runtime. I could look into it more, but I'm just going to try to get some work done with the packager as-is for now. Having Browserify concatenate it doesn't work because of the native modules.

@alinz see this: #1451

@euforic
Copy link

euforic commented Jun 6, 2015

@jtremback @alinz I hacked together some of my build scripts into a makeshift cli tool if you guys are still looking for a fix. It's definitely not my best work but It has been getting me by until es6 modules work in the packager.

Github: bh5-js/rctapp
NPM: rctapp

It can do the following:

  • Run Babeljs transpiler
  • Start React Native Packager / Server
  • Builds Xcode project
  • Install App on iOS Simulator
  • Launch App on iOS Simulator

@jtremback
Copy link
Contributor

@euforic 👏

@alinz
Copy link
Author

alinz commented Jul 15, 2015

@brentvatne Do you know any way to get es6.modules working? I have tried custom transofrm, .babelrc, even @euforic's way, nothing seems to work and I keep getting this error. It seems no matter how hard I try I can't get es6.modules to work.
screen shot 2015-07-15 at 10 44 18 am

Need HELP please...

@brentvatne
Copy link
Collaborator

Hi @alinz - I believe this is related to #1924

Try making this simple change to node_modules/react-native/packager/packager.js: https://gist.github.com/brentvatne/794a77917d7a4b3cce5b/revisions (the one line resetCache option)

This is an example of a working babelrc: https://github.com/brentvatne/react-native-animated-demo-tinder/blob/master/.babelrc

@alinz
Copy link
Author

alinz commented Jul 15, 2015

@brentvatne thanks a lot. It works.

@alinz alinz closed this as completed Jul 15, 2015
@euforic
Copy link

euforic commented Jul 15, 2015

@brentvatne @alinz Just a heads up. I added support to the rctapp tool to clean the cache $ rctapp clean cache

@ryanmcdermott
Copy link

If anyone else encounters this issue, where you have a .babelrc file but React Native won't use your ES6/ES7 settings, please try the rctapp provided by @euforic This worked great for me. I ran rctapp clean cache and it fixed my issue.

@quantuminformation
Copy link
Contributor

I'm not clear how to get es6 modules in a new RN 0.16.0-rc project.

@satya164
Copy link
Contributor

@quantuminformation:ES6 modules are already supported by default in React Native. However there are some bugs preventing it to work in 0.16.0-rc, which will be fixed in 0.16.0

@facebook facebook locked as resolved and limited conversation to collaborators Jul 15, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

8 participants