realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.72k stars 564 forks source link

Investigate the possibility of having Realm Web work in React Native #4178

Open tomduncalf opened 2 years ago

tomduncalf commented 2 years ago

As per https://github.com/realm/realm-js/issues/4174, trying to use Realm Web inside a React Native app throws an error: Can't find variable: TextDecoder. Adding https://www.npmjs.com/package/react-native-polyfill-globals gets further, but we then hit an error {{ WARN Invalid responseType: blob}}.

If it is possible to make Realm Web work inside React Native, this could be beneficial for users who would like to create a React Native app using Realm which also targets web (see https://github.com/realm/realm-js/issues/4177), if offline/sync support is not important (they would need to use Realm Web instead of RealmJS).

hipaven commented 2 years ago

I got similar error

import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client"; import * as Realm from "realm-web";

I am using above 2 realm features to call realm Graphql API in react native Initially I got Error: While trying to resolve module @apollo/client. I added 'cjs' in metro config sourceexts. Now I am getting below error - . I assume the issue is with realm-web. Can you assist to resolve this issue. ReferenceError: Property 'TextDecoder' doesn't exist, js engine: hermes ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes. ReferenceError: Property 'TextDecoder' doesn't exist, js engine: hermes ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes
ERROR Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native., js engine: hermes

ahmed-adly-khalil commented 1 year ago

were anyone able to solve this? having same issue with https://github.com/nats-io/nats.ws

mfrfinbox commented 9 months ago

To solve the problem, install the "text-encoding-polyfill" and add the import statement "import 'text-encoding-polyfill'" to your index.js file as early as possible in your app. At least this worked for me, I hope it helps.

elainema commented 3 months ago

@mfrfinbox, the solution works for me, thanks