invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.68k stars 2.21k forks source link

react-native-firebase while run npm run web #4011

Closed codecopier closed 4 years ago

codecopier commented 4 years ago

Failed to compile.

./node_modules/react-native-firebase/dist/utils/events.js Module not found: Can't resolve 'react-native/Libraries/vendor/emitter/EventEmitter' in 'E:\Updated\node_modules\react-native-firebase\dist\utils'

how to run in web smoothly with out disturbing the mobile side react-native-firebase

when i run react-native run-android-working fine,

E:>react-native -v react-native-cli: 2.0.1 react-native: 0.61.5

E:>npm -v 6.14.3

E:>node -v v13.11.0

"react-native-firebase": "^5.6.0", from packages.json

npm run web that above issue in terminal and browser shown.

andersonaddo commented 4 years ago

I guess one option would be to avoid somehow remove that as a dependency when you're running on web (you'd also have to wrap all your import @react-native-firemase/x commands in conditionals).

Maybe this may help.

afilp commented 4 years ago

Is there support for react-native-web and firebase? I also need this. Thanks a lot!

mikehardy commented 4 years ago

No, there is not. I'm not sure there is really an action here other than the community proposing a design that allows react-native-firebase to use the firebase-js-sdk if the platform is web.

I have success using reactxp on top of react-native personally, the have a post-typescript compile / pre-bundler module aliasing phase that I use to swap out the "firebase bindings" in use such that it's react-native-firebase for native and firebase-js-sdk for web. You'll need to do something similar.

I'm going to close this because "doesn't work with react-native-web" is not a bug. "works with react-native-web" is a feature request that may or may never be implemented, but would be tracked in the feature request style as documented on rnfirebase.io

cglacet commented 4 years ago

I have success using reactxp on top of react-native personally, the have a post-typescript compile / pre-bundler module aliasing phase that I use to swap out the "firebase bindings" in use such that it's react-native-firebase for native and firebase-js-sdk for web. You'll need to do something similar.

That's interesting, any chance you would have some code showing how this work in practice ? (not necessarily for firebase)

mikehardy commented 4 years ago

@cglacet this is the example you want: https://github.com/microsoft/reactxp/blob/master/samples/TodoList/README.md

in an RNFB application what you'd want is for example a new "module" for perhaps "analytics" and you define an interface API for the things you need, then a web or native implementation that is resolved at build time in the apply aliases phase of the build https://github.com/microsoft/reactxp/blob/d21a735c8634ceaa2e294b9d3175c383642a0b52/samples/TodoList/buildconfig.js#L91

I will say I just discussed this with Salakar / Mike D one of the original authors here from Invertase and who just did something similar on FlutterFire, we will probably extend RNFB to include react-native-web support soon, with a general design that the existing APIs here remain unchanged but for web delegate under the covers to firebase-js-sdk. There is nothing to show here yet but PRs would either be welcome for an initial addition of coverage to the core module here and something easy to start like analytics

I still like reactxp but it appears react-native-web has "won" since I chose reactxp 18mos ago and recognizing that is just recognizing reality: https://npmcompare.com/compare/react-native-web,reactxp

cglacet commented 4 years ago

@mikehardy Thanks for sharing, I'll try to understand this, but I'm not sure I can.

To be honest I don't really understand why the web support is not part of react-native itself. To me (a end user), it looks like there wont be a winner until this is the case 😄 .

mikehardy commented 4 years ago

I agree with you. This is a very strong argument for Flutter that react native as a community should recognize. I like typescript everywhere and don't currently want to learn dart but it's tempting.