staltz / react-native-node

Run a separate Node.js process behind a React Native app
MIT License
1.12k stars 33 forks source link

NodeJS doesn't rebuild with new insert #18

Closed luandro closed 6 years ago

luandro commented 6 years ago

I'm running a simple express server like the example, and it works. But after changing the nodejs server and rebuilding with cd server && npm i && cd .. && react-native-node insert ./server the changes don't take effect any more.

I've tried deleting node_modules on both the nodejs and the react-native apps, tried deleting the rnbundle that gets saved to the raw folder. Nothing changes the express app once it's been built for the first time.

staltz commented 6 years ago

You might need to recompile the android app

staltz commented 6 years ago

Gradle

luandro commented 6 years ago

Is there a react-native command for that? How does that work?

staltz commented 6 years ago

react-native run-android

luandro commented 6 years ago

I run it every time right after running react-native-node insert, still Nodejs app doesn't get updated.

staltz commented 6 years ago

./gradlew clean then run-android?

luandro commented 6 years ago

Took me a while to find out I had to brew install gradle in order to use ./gradlew clean in the android directory.

Finally did, ran it successfully, but still get the first response written in the express server. Still seems the NodeJS apps aren't being rebuilt, despite running the whole thing every time:

"scripts": {
    "dev": "npm run clean && npm run build && npm run android",
    "build": "cd server && npm i && cd .. && react-native-node insert ./server",
    "clean": "cd android && ./gradlew clean && cd ..",
    "android": "react-native run-android"
},
staltz commented 6 years ago

Try one more thing: delete android/app/src/main/res/raw/rnnodebundle before all that.

luandro commented 6 years ago

Added rm android/app/src/main/res/raw/rnnodebundle to the clean script, but still nothing. No idea where the old code is coming from. It should only exist in rnnodebundle, and if that's deleted and recreated with new code, how does it still persist?

Emulating on a MotoG3-TE - 6.0.

staltz commented 6 years ago

Oh emulators? I don't think this library works there, because node.js is compiled for ARM architectures, and emulators usually are not ARM.

luandro commented 6 years ago

Oh sorry, bad use of the word. I'm running the app on the actual phone (I was emulating using Geny Motion, but I read in #5 that emulators don't work).

Is there any thing else we can try?

staltz commented 6 years ago

Well, there is nothing else to try if you: (1) remove and rebuild rnnodebundle, (2) rebuild with gradle from scratch, (3) uninstall and reinstall the mobile app. Are you sure you have done those 3? There is no way the previous rnnodebundle can creep in after that

luandro commented 6 years ago

Got it fixed by using method (3), uninstalling the app on the device. Seems like the device caches the NodeJS application for some reason. Manually going to Settings > Applications > MyApp on the phone and uninstalling it; when rebuilding with react-native the NodeJS application gets rebuilt.

Is there no programmatic way to to this?

Thanks for the help.

luandro commented 6 years ago

I added adb uninstall com.app_package to my npm scripts, and that solved the problem. I guess this is usual for working with Node in react-native, to have to rebuild at every Node change, right?

I'll close this for now, thanks a lot for the help. Cheers!

staltz commented 6 years ago

Yeah, we have to rebuild after changes. Recompiling is a normal thing to do when developing mobile apps with Java and Gradle. React Native is what brings something completely new: runtime reloading. It would be a lot more work for me to build runtime reloading of the background process, so we do it the normal way: rebuilding

staltz commented 6 years ago

I think the uninstall was important because react-native-node unzips the rnnodebundle in an application directory, and only once (this is to avoid unzipping every time). So I think another way of solving the problem would be rebuild (after a gradle clean), clear the app's cache and data, then run