Search code examples
javascriptreact-nativewatchmanreact-native-cli

How to watch react-native node_modules changes


When I run react-native start or npm start the packager starts and prompts to be Looking for JS files in /Users/map/repos/myrepo/

I've got Hot reloading enabled. When I change a file located within /Users/map/repos/myrepo/node_modules/react-native/ seems to detect the change, however if I edit a file in a third party repository like /Users/map/repos/myrepo/node_modules/react-native-menu/ looks like watchman is not detecting the change.

I've just upgraded React Native in my project to 0.39 and I think this wasn't the default behavior before. I've set up some logging in react-packager/src/node-haste/index.js and seems react-native-menu files are included in hasteFSFiles, however change event is not triggered.

I've tried deleting node_modules and reinstalling it, Cleaning Watchman state and other without luck.


Solution

  • Ok, Looks like they redid React Native packager in version 0.39, although this bug is still present in v0.40. Until there is an official fix, if you want to detect changes of a library within node_modules you need to edit node_modules/react-native/packager/defaults.js and add your project name to providesNodeModules, like this:

    exports.providesModuleNodeModules = [ 'react-native', 'react-native-windows', 'react-native-menu', ];

    The issue where this has been reported can be found here: https://github.com/facebook/react-native/issues/11301