react-nativebrowserify

How to use browserified libraries in React Native


I have a library that I want to use in a React Native project that has been browserified. When I require the library all of the internal require() calls get hijacked and rather than resolve dependencies inside of the file that I am including React Native tries to resolve them, thus causing it to break. I'd like to know what the proper way to include a browserified library in a React Native project is.


Solution

  • The best solution I've come up with is to switch to webpack. As alluded to in one of the comments the library needs to be processed by something like browserify or web pack because it has decencies on node builtins like 'domain'. The problem is that browserify declares a require() method, which does not play nice inside of React Native which also has a require() method. Switching to webpack resolved this because they name their require() differently, __webpack_require() and this allows the processed version to work correctly inside of React Native.