How can you modify the Native code of someone else's NPM package without ejecting?

SDK Version: 37+
Platforms: Android and iOS

I asked this question on [Reddit] as well so reading it there may provide more information if there’s something about this question that you don’t understand.(https://www.reddit.com/r/reactnative/comments/hc43vg/how_can_you_modify_the_native_code_of_someone/)

My current situation is that I’m trying to modify an NPM package that contains Native code (both Java and Objective-C).

However, the changes that I make to the Native code are never reflected in the final application.
According to the answers that I received on Reddit, it would seem that the reason is that Expo does not support direct changes to Native code unless your app is ejected (please correct me if this is wrong).

However, ejecting isn’t really an option for me, because I don’t have a Mac, so I would be unable to test my changes within the iOS code.

I had the idea that maybe I could Fork the package, and re-install it each time I modified it, but that doesn’t seem to work either.

Does re-installing the package really work (and I’m just doing it wrong) or does it not work?

If re-installing the package doesn’t work, can someone please explain to me as to where in the world Expo gets the Native code that makes these packages work?

Since changing the code on the fly doesn’t seem to work, I assumed that Expo must read the Native code at the time of the package’s installation (i.e. through NPM, yarn, etc) and cache it somewhere, but then why doesn’t re-installing the package after modifying it seem to do anything?

If Expo doesn’t read the Native code when the app is built nor when the package is installed, then I have absolutely no idea where the Native modules/code is actually coming from.

For those of you who may be in the same situation, it seems that every Native module that is compatible with Expo comes pre-bundled with Expo (this includes user-made modules that you can install from NPM).

This is the reason why the build size for very basic apps is so big (at least until the Expo team adds the ability to bundle only the Native modules that you use).
Unfortunately, this also means that you are unable to modify the Native code of these modules without ejecting from Expo (or by using vanilla React Native).

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.