deepstreamIO / deepstream.io-client-js

The Browser / Node.js Client for deepstream.io
Other
294 stars 109 forks source link

Doesn't works with React Native (Expo) With Hermes #595

Closed ScreamZ closed 5 months ago

ScreamZ commented 1 year ago

Hi,

Just wanted to share that the Client SDK no longer works with react native and expo.

Expo version : "expo": "~47.0.12",

 ERROR  ReferenceError: Property 'exports' doesn't exist, js engine: hermes
 ERROR  Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
        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: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter.
        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
jaime-ez commented 1 year ago

Hi, I'll try to take a look, can you share a message that references deepstream explicitly? That error doesn't...

ScreamZ commented 1 year ago

It doesn't, just try to import the SDK (installed with the REACT_NATIVE env var) somewhere and you end up with this… :'(

jaime-ez commented 1 year ago

Ok, found a few bugs, solved in lateste release v7.0.1

These are my steps using expo:

npx create-expo-app my-app --template bare-minimum
cd my-app
DEEPSTREAM_ENV=react-native npm install @deepstream/client
npx expo start

it works as expected

jaime-ez commented 1 year ago

Please reopen with detailed steps to reproduce if the problem persists

ScreamZ commented 1 year ago

Looks like it's not working in my project still, I'll check deeper but we have an issue I guess.

About the installation on React Native

Also, I've some concerns about the technique of doing the install using an env variable. As far as I can see, this will run a post-install script that changes code in the node_modules.

With this technique this work on the computer that initially did the installation. But coworkers that pull your changes on git just end up with the "standard" version.

I guess it would be better to add some checks in the code to check whether or not we are in react native environment.

See https://github.com/facebook/react-native/commit/3c65e62183ce05893be0822da217cb803b121c61

@jaime-ez what do you think ?

PS : I'll give detailed reproduction soon

jaime-ez commented 1 year ago

Hi, take a look at the original issue https://github.com/deepstreamIO/deepstream.io-client-js/issues/534 for some background.

An option you can take is that in your own project's package.json add a postinstall script:

{
  "scripts" : {
     "postinstall": "DEEPSTREAM_ENV=react-native node node_modules/@deepstream/client/scripts/postinstall.js"
  }
}

That way anyone who clones your repo will have the desired version

jaime-ez commented 5 months ago

closing due to inactivity, please provide more information if the problem persists