-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Make Relay work with React Native out of the box #26
Comments
have not tried yet, but looks like so. |
Relay should work as-is on React Native - if not, feel free to let us know and re-open this! |
@josephsavona even if relay components aren't inheriting react-native's Component? https://github.com/facebook/relay/blob/master/src/container/RelayContainer.js#L23 I'm getting |
I also needed to include johanneslumpe/react-native-browser-polyfill to get around a similar issue |
@josephsavona Relay cannot work as-is with React Native because Relay includes React web as a hard dependency, and including React web into React Native is not functional. Here's a commit that shows the minimal changes to build relay against react-native: The 'dist' step of building relay still fails with that commit, with the error: I'm not sure exactly why that's failing. The last two things we had to do to get relay working with react native was:
process = {env: {}};
module.exports = require('react-relay'); |
Last thing I forgot to mention regarding relay's compatibility with react-native: relay assumes |
@josephsavona can we re-open this? |
@amccloud thanks for investigating, I'm reopening to give us a place to track this. |
The last thing we needed to do to get relay working with react-native was to use react-native's global We've gotten basic requests working following the steps I've outlined above in my comments on this issue, but I'm not 100% certain other things aren't broken yet. |
@boourns that's great. I also had to delete |
@boourns @clintonwoo Hello guys, followed your step all the way, however i get an error 'can't find variable fetchWithRetries', however when adding it i get 'cannot find variable: self'. Any tips would be greatly appreciated. github repo is https://github.com/almasakchabayev/reactNativeRelayWebpackDemo. |
@almasakchabayev follow this comment: #26 (comment) |
@boourns It worked when I changed fetchWithRetries in 'function _sendQuery' to just fetch. Great! Thanks a lot! |
@boourns Maybe a dumb question: What do you mean by: "Commit relay's |
@lukasreichart Ideally we would build relay against react-native, do a With that commit applied, the The proper solution will be to figure out why the dist build fails and making it not fail, but I don't really know what the problem is there yet. In the meantime if you want to try relay with react native, the hack solution is to fork relay, apply e0037c7, commit |
@boourns Thanks you've directed me to the right path. But now I have a problem with the This error occurs when you use Any ideas on this one? |
@lukasreichart in
And then you need to run your react-native packager via 'npm start' instead of running This is another workaround we had to apply, not sure how to make this just gracefully happen yet. |
@boourns Would you mind sharing the content of your |
Sorry, discussing with @jahfer now who did this portion of the work. Disclaimer again that this is hacks on hacks on hacks, not a robust solution to getting it working :) What we did was copy the original react-native babel transformer from https://github.com/facebook/react-native/blob/master/packager/transformer.js into your project, and add the relay plugin:
|
I think my transform is working now. Thank you very much. @boourns |
@lukasreichart yes, you need to follow this comment: and this comment: let me know how that works |
Based on: facebook@e0037c7 (see: facebook#26)
Based on: facebook@e0037c7 (see: facebook#26)
After updating Fetching podspec for
|
The fbjs issues seem to be resolved now. However, I am still running into issues with react-native and babelRelayPlugin after updating my Here is what the code looks like: package.json:
.babelrc: option A:
option B:
babelRelayPlugin.js:
NPM Errors .babelrc option A:
.babelrc option B:
Which option of the .babelrc is correct (A or B)? Also, is the 'start' within the package.json correct? Thanks! JV |
I believe option A shows that error because babelRelayPlugin.js exports
To confirm you could try I'm also stuck with the same error while using option B. |
Here's the results: .babelrc using option A:
babelRelayPlugin.js updated:
Running
Confirms that using:
within the babelRelayPlugin.js is incorrect as @siderakis pointed out. |
Has anyone resolved this issue?
Also, if I remove .babelrc I don't get this error anymore. (but I still get errors further down the process). |
I've played around with that file by changing the spread operator on line 120 to: and that leads to the following error:
And down the rabbit hole we go. I am not sure why a spread operator is used like that there. |
Have you tried to install RN 0.22.0-rc? Should work out of the box with Babel configured like this: {
"presets": [
{ "plugins": ["./relay/babelRelayPlugin"] },
"react-native"
],
"passPerPreset": true
} |
@l-urence I just tried to use RN 0.22.0-rc and here are my results: package.json
.babelrc
babelRelayPlugin.js:
running
Does your package.json differ from mine? |
@jefferyvincent: You are using |
Thanks @oblador, but I am still seeing the same error above even after deleting my node_modules folder and running package.json updated:
Error:
|
@jefferyvincent: That should work, try resetting some caches like |
@oblador: I ran those commands and restarted and I still end up with that same error. No idea what |
@jefferyvincent: This sounds like NPM 3 troubles, try switching to NPM 2 or just installing |
Bingo! Thanks @oblador that did the trick. I ran |
Given the number of subscribers to this issue, it might be best to limit discussion to just issue-related topics, rather than support. This is generating a lot of noise. |
@taion, I was merely trying to properly document the above steps more clearly, since there were some discrepancies as to how the .babelrc file should be written. With that said, my comments above due constitute as issue-related. ;) |
We shouldn't have to keep this thread open much longer. #929 |
I just checked out a fresh copy of Relay from master, and did the following:
A wild React Native and Relay app appeared. Countless thanks to @skevy, @boourns, @gre, @davidaurelio, @martinbigio, @zpao, @spicyj, and everyone on this thread who helped us tear down the barriers to using Relay with React Native in the open source community. I can't wait to field all of your React Native specific GitHub issues. We're done here. Open new issues at https://github.com/facebook/relay/issues or https://github.com/facebook/react-native/issues as you discover them! |
Awesome work @steveluscher! |
🎉 |
(Edited : I will found help on discord) 🎉 |
@steveluscher awesome work! |
@steveluscher Great |
The remaining steps are:
unstableBatchedUpdates
depending on React/React Nativefetch
polyfill for React Nativebabel-relay-plugin
with React Native (see discussion at Make babel-relay-plugin run before other transforms #714 (comment))Note: edited by @josephsavona
The text was updated successfully, but these errors were encountered: