Developing NPM packages for React Native

I'll keep this short: there are a few ways you could potentially develop NPM packages to be used with React Native that I'm aware of:

  1. develop them in some folder, use symbolic links to include them in the node_modules folder of your React Native app (won't work because Watchman doesn't use scan relative links)

  2. develop them in some folder, then use npm link to include the packages in your app (won't work because npm link uses symbolic links underneath the hood, and will fail for the aforementioned reason)

  3. develop them in some folder, set up relative install directories in your package.json and for every change to your package you want to test, run in your React Native app directory rm -rm node_modules && npm i && npm start;

  4. after running react-native init, go to the file node_modules/react-native/packager/react-packager/src/FileWatcher/index.js and edit line 70 like this:

isWatchman() {  
  return detectingWatcherClass.then(
    Watcher => false    // line 70
    // used to be:
    // Watcher => Watcher === sane.WatchmanWatcher
  );
}

Not exactly sure how/why it works (I have since lost the blog post/Github issue that I got this from), but this last option tells Watchman to scan our node_modules folder for any changes and live-reload when any of them changes.

So to write your NPM packages, develop them in a folder in your React Native app's node_modules folder and add the relative NPM package path to your package.json file under "dependencies":

"any-db-client": "file:./node_modules/any-db-client",

And that's it! When you're done developing the NPM package, publish it to NPM, move your package's folder to another location, change your package.json to reflect installation from NPM, and enjoy! If you know of a better, more maintainable way of accomplishing the same goal, please let me know in the comments below!