Do you want to request a feature or report a bug?
bug
What is the current behavior?
watch is hardcoded to true when creating JestHasteMap: https://github.com/facebook/metro/blob/master/packages/metro/src/node-haste/DependencyGraph.js#L96
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.
https://github.com/hfter789/metro
jest packages/metro/src/integration_tests/__tests__/buildGraph-test.js
What is the expected behavior?
JestHasteMap should receive the watch value coming from metro config.
This seems to have been introduced by FB internal changes here: https://github.com/facebook/metro/commit/0d6c135045a33f2b9effa8ca31b648e6b29ec24c . We were hoping to use the watch: false option in our React Native release build to prevent having to set fs.inotify.max_user_watches on our CI server.
I'm not very clear on the metro/haste-map internals, but it seems odd that a static build (when doing bundle) would need file watching.
Is there any context as to why this config option is ignored as of 6 months ago?
We were hoping to use the
watch: falseoption in our React Native release build to prevent having to setfs.inotify.max_user_watcheson our CI server.
Sorry for the possible noise on a ticket that might be unrelated but, wanted to add that similar to @FLGMwt , our project needs to have the bundle command not watch for files on CI (JitPack in our case). Would appreciate any pointers on how to suppress file watching in react-native bundle if possible. 馃槵 馃檱
Edit: for the project I'm currently working on, I've put a ugly nasty solution in place: to replace the node-haste/DependencyGraph.js file with one that has the watch: flag as false. My hands feel very dirty now, but that unblocks our CI pipeline for the time being.
I know nothing of react-native but have been tasked with figuring out the same max_user_watches issue when building a react-native project in CI. I can't think of a reason file watchers for js builds should be needed when just bundling for CI.
As I started digging through the rabbit hole of react-native, the cli, and these tools, I arrived at the watch metro config option. Despite 0d6c135 it would seem the docs still mention watch as an option. Are there any alternatives to short of the above suggestion about replacing DependencyGraph? I'm also interested in the context of why this option was removed @rafeca @mjesun
Thank you for the solution @hypest! This has been a huge issue for us for over a week breaking our CI builds and nothing worked except patching this file directly. I had to update the patched source file since it has changed since your reference PR, but this approach did work - thank you.
I made this changed in the patched file:
// watch: opts.watch, (line 106 in DependencyGraph.js)
watch: false,
Forcing watch to false fixes the problem.
I don't know why disabling watch was not respected, it would be helpful for this to be fixed.
@rafeca @mjesun I think it is very unreasonable to enforce watching project files even in publish mode, since filesystem watches consume quite amount of system resource that could have been devoted for faster builds. It is also breaking continuous integration pipelines when it needs to unnecessarily watch ridiculous number of files, especially in node_modules, as a project grows in size.
We tried updating the metro field in package.json and also writing a metro.config.js file like this:
module.exports = {
watch: false,
};
to disable watch mode, according to the documentation here https://facebook.github.io/metro/docs/en/configuration#watch but neither worked. If either of these configurations was incorrect, I'm happy to try again with the correct configuration.
For reference we are using Metro via Expo for a React Native project. We also tried other options to disable watch mode using the Expo CLI, but these did not work as well.
before update release, I have to use the patch in this way:
sed -i -e 's/watch: true/watch: false/' node_modules/metro/src/node-haste/DependencyGraph.js
replace the watch: true with watch: false while building on the CI pipelines.
This is causing issues on internal custom CI servers as well, we need a way to switch off watch via configuration.
@Kinka great fix, thanks for sharing. Using yarn workspaces with nohoist, your code can be extended as:
sed -i -e 's/watch: true/watch: false/' $(find node_modules -name DependencyGraph.js)
I've now packaged this hack as a node module: https://www.npmjs.com/package/react-native-nowatch. Hope this helps someone out there - I've had a really frustrating time getting react-native builds working on CI, and the suggestions in this thread really helped. Thanks to all above.
Most helpful comment
Sorry for the possible noise on a ticket that might be unrelated but, wanted to add that similar to @FLGMwt , our project needs to have the
bundlecommand not watch for files on CI (JitPack in our case). Would appreciate any pointers on how to suppress file watching inreact-native bundleif possible. 馃槵 馃檱Edit: for the project I'm currently working on, I've put a ugly nasty solution in place: to replace the
node-haste/DependencyGraph.jsfile with one that has thewatch:flag asfalse. My hands feel very dirty now, but that unblocks our CI pipeline for the time being.