Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 727
maraujop Avatar asked Jan 09 '17 19:01

maraujop


2 Answers

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

like image 172
maraujop Avatar answered Oct 21 '22 04:10

maraujop


Another solution is to start react native packager with additional arguments

npm run start -- --providesModuleNodeModules react-native,{any_node_module}

Works with RN v0.42.0 for me

like image 26
ifours Avatar answered Oct 21 '22 03:10

ifours