watchman: Watchman fails with 'Operation not permitted'

Since updating yesterday using Hombrew on macOS, watchman always fails with the error:

{
    "version": "2022.05.30.00",
    "error": "std::__1::system_error: open: /Path/To/Project: Operation not permitted"
}

Does the 2022.05.30.00 version of Watchman work? if so, why would it fail (for me at least) suddenly after being updated?

As far as I know the only difference between the configurations of my machine today and yesterday (when Watchman worked fine) is that I ran brew upgrade watchman. I have confirmed all the necessary file permissions are in place and have rebooted, reinstalled, terminated, etc.

UPDATE: A solution to get things working while we await a fix to Watchman is provided below:

watchman shutdown-server       # To ensure an old version isn't still running
brew uninstall watchman        # Get rid of the buggy (e.g., 2022.05.30.00) version
curl https://raw.githubusercontent.com/Homebrew/homebrew-core/8651d8e23d308e564414188509f864e40548f514/Formula/watchman.rb > "$(brew --repository)/Library/Taps/homebrew/homebrew-core/Formula/watchman.rb"
brew install watchman          # This installs the functioning 2022.05.16.00 version dowloaded above
brew pin watchman              # Tell brew to leave this older version alone (don't forget to unpin once this problem is solved)
cd "$(brew --repository)/Library/Taps/homebrew/homebrew-core/Formula/"
git checkout --  watchman.rb   # To avoid brew showing warnings about having uncommitted git changes

Note that for those who have found other solutions, you are not experiencing the same issue, but of you are doing things like granting watchman full disk access, you may be reducing your security unnecesarily.

Also, if you are on macOS, and the above doesn’t work on its own, it may pay off to do the following and try the above again:

sudo tccutil reset SystemPolicyDocumentsFolder
sudo tccutil reset SystemPolicyAllFiles

If you do this, you will need to again grant access to those apps that need it (they will ask).

UPDATE:As of 2022.06.27.00 Watchman appears to work again.

If you followed the instructions above, just

brew unpin watchman

and update it as usual. Then (and from then on), to be sure things work as expected, after every update of Watchman:

watchman watch-del-all
watchman shutdown-server 

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 35
  • Comments: 90 (2 by maintainers)

Most upvoted comments

This is definetly a problem with version 2022.05.30.00. If you rollback to 2022.05.16.00, it works again. Howto: See https://remarkablemark.org/blog/2017/02/03/install-brew-package-version/

TLDR:

brew uninstall watchman
curl https://raw.githubusercontent.com/Homebrew/homebrew-core/8651d8e23d308e564414188509f864e40548f514/Formula/watchman.rb > /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/watchman.rb
brew install watchman
brew pin watchman # Don't forget to unpin once this problem is solved...
cd /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/
git checkout --  watchman.rb

Version 2022.06.20.00 did not have the fix in it, but from what I can tell 2022.06.27.00 does.

I had to make sure I didn’t have an older watcher still around (watchman shutdown-server) but after doing so, the first post-upgrade watchman I triggered asked for access to files in the Documents folder - and once allowed, worked fine without any “Operation not permitted” errors occuring.

Screen Shot 2022-06-28 at 11 58 21 AM

Seems that the following does the trick:

  1. watchman shutdown-server
  2. Restart watchman service with watchman.
  3. Now watchman will ask access to file and folder click YES

Finally got this to work. I’m on an Intel iMac running Monterey. Here were my steps:

brew uninstall watchman

curl https://raw.githubusercontent.com/Homebrew/homebrew-core/8651d8e23d308e564414188509f864e40548f514/Formula/watchman.rb > /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/watchman.rb

brew install watchman

brew pin watchman

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/

git checkout --  watchman.rb

This did nothing initially, but then I ran:

sudo npm run test as discussed here.

A permission window then popped up where I was finally able to give access to my Desktop (project is living on my Desktop).

I then rebooted the terminal - didn’t need to restart macOS (although it couldn’t hurt). I also didn’t touch anything in “Security & Privacy” under System Preferences like some have mentioned.

I ran npm run start and it worked, finally. My god, that was a fun 8 hours.

Downgrading to a previous version is surprisingly not easy.

@shoopi12 I recommend giving it a shot. The instructions above work. The only things to be careful of are:

  1. If you are on an Intel Mac use
    /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/
    
    for the Formula path.
  2. Be sure to cd to that directory before the git checkout step.
  3. Run watchman shutdown-server afterwards to make sure an older version isn’t lingering around.

Version 2022.06.20.00 did not have the fix in it, but from what I can tell 2022.06.27.00 does.

I had to make sure I didn’t have an older watcher still around (watchman shutdown-server) but after doing so, the first post-upgrade watchman I triggered asked for access to files in the Documents folder - and once allowed, worked fine without any “Operation not permitted” errors occuring.

Screen Shot 2022-06-28 at 11 58 21 AM

This works, however in my case I accidentally hit “Don’t Allow” and wasn’t able to trigger that prompt again. I have Mac OS Monterey. In order to allow access, go to Preferences > Security & Privacy > Privacy > Files and Folders and add tick next to Watchman > Documents Folder

MacOs Monterey 12.4 Still got this problem. Watchman 2022.06.06.00. Pls help.

This fix will work. Kindly try it

Install latest watchman version (brew install watchman)

  1. Go to System preferences > Security & Privacy then scroll down
  2. Select Full Disk Access
  3. Unlock it and click + button to add new app/tool
  4. Select Macintosh HD in the folders list. (For new users, if u cant see this folder, fo to finder preferences > sidebar and check it.)
  5. Press this combination shift Command . (don’t forget the dot) at the same time to see all the directories list
  6. Click opt > homebrew > bin (Tested only on MacOS Monterey. If using another version, search watchman under Macintosh HD).
  7. Look for watchman in the list then select it.
  8. Once added, run ur program again.

Make sure ur project folder is under /Users/<username>/<project>. Don’t put it under documents or any other folder there. It will refuse due to some weird restrictions.

On mac the issue for me was that I didnt approve permissions for folder to watchman. So System preferences -> Security & Privacy -> Privacy -> Files and Folders -> Watchman -> Desktop Folder.

That is the problem I ran into so I was going to also downgrade folly but it’s used by many other packages some of which also used by other packages, etc. So I decided not to tinker further.

I was able to work around this by using brew install --HEAD watchman

I have just installed 2022.06.06.00 and the same problem still persists. Currently I am trying to get it to work using one of the solutions above.

In an attempt to fix this I’ve run

brew update
brew uninstall watchman
sudo tccutil reset SystemPolicyDesktopFolder
sudo tccutil reset SystemPolicyDeveloperFiles
sudo tccutil reset SystemPolicyDocumentsFolder
sudo tccutil reset SystemPolicyDownloadsFolder
sudo tccutil reset SystemPolicyNetworkVolumes
sudo tccutil reset SystemPolicyRemovableVolumes
sudo tccutil reset SystemPolicySysAdminFiles

then rebooted and run

brew install watchman
watchman

That results in a series of library errors that are cleared by reinstalling several of watchman’s dependencies. Once that’s done I did

brew update
brew uninstall watchman

then rebooted again and did

brew install watchman
watchman

and still get the same error:

{
    "version": "2022.05.30.00",
    "error": "std::__1::system_error: open: /Path/To/Project: Operation not permitted"
}

I then gave watchman Full Disk Access, but continue to see the same error.

Also at no point during this process does launching watchman result in the expected request for access to the Documents folder (as all other apps that need it do correctly following the tccutil resets).

@chadaustin any updates?

Backout in https://github.com/facebook/watchman/commit/cf0c3bdec32f2f457a0b06fcd1c09a62c11cf143

We don’t maintain the homebrew build, but hopefully a new one comes out soon.

The only thing that seems to work is moving your entire project to your Home folder.

Confirming that this is also the only thing that works for me.

Not a practical solution, but it will allow some headway to be made.

Version 2022.06.20.00 did not have the fix in it, but from what I can tell 2022.06.27.00 does.

Hope that’s true! Waiting for confirmation from others.

It would be nice if a contributor could confirm and close.

I’m still getting a Operation not permitted on version 2022.06.27.00. My Mac run out of space and I can not locate React Native project inside home folder. watchman sucks.

@orome sorry I omitted it from my Comment, I did the step of course

Edit: After restarting my computer it worked. I’m summing up the steps here once again for anyone else:

brew uninstall watchman

curl https://raw.githubusercontent.com/Homebrew/homebrew-core/8651d8e23d308e564414188509f864e40548f514/Formula/watchman.rb > /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/watchman.rb

brew install watchman

brew pin watchman

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula

git checkout

- restart macOS

If needed, give watchman Files and Folders / Full Disk Access permission, maybe uncheck and recheck it. When I tried npm start again I got the blessed alert “watchman would like to access your Files and Folders”. After confirming everything worked.

@orome tried that, but for some reason I still get the error with the higher version: Screen Shot 2022-06-03 at 22 28 15

while watchman -v shows the lower version: Screen Shot 2022-06-03 at 22 28 26

What I did:

brew uninstall watchman

curl https://raw.githubusercontent.com/Homebrew/homebrew-core/8651d8e23d308e564414188509f864e40548f514/Formula/watchman.rb > /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/watchman.rb

*edit*: brew install watchman

brew pin watchman

cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula

git checkout

@oetjen I get:

/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/watchman.rb: No such file or directory

I don’t even have an /opt/homebrew/, just an /opt/homebrew-cask/, which is empty.

I do have a

/usr/local/Homebrew/Library/Taps

which contains a caskroom and a homebrew. Should I be using

/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/watchman.rb

instead?

I have the same error after following the React Native getting started guide, on both xcode and expo cli.

Yes, this bug kills expo start: no development is happening here.

The only thing that seems to work is moving your entire project to your Home folder. Nothing else seems to work. It seems to be affecting a lot of other users right now, likely a bug with some new macos security update with file access permissions.

I have the same error after following the React Native getting started guide, on both xcode and expo cli.

I hope the watchman team looks into this!

https://www.rich-informatik.de/blog/how-to-fix-react-native-watchman-operation-not-permitted

it solved my problem ,maybe could help you

That solution is exactly describing what has already been posted right here in this thread in June 2022, please don’t repeat: https://github.com/facebook/watchman/issues/1030#issuecomment-1145766948

Version 2022.06.20.00 did not have the fix in it, but from what I can tell 2022.06.27.00 does. I had to make sure I didn’t have an older watcher still around (watchman shutdown-server) but after doing so, the first post-upgrade watchman I triggered asked for access to files in the Documents folder - and once allowed, worked fine without any “Operation not permitted” errors occuring. Screen Shot 2022-06-28 at 11 58 21 AM

This works, however in my case I accidentally hit “Don’t Allow” and wasn’t able to trigger that prompt again. I have Mac OS Monterey. In order to allow access, go to Preferences > Security & Privacy > Privacy > Files and Folders and add tick next to Watchman > Documents Folder

macos 13.1 just fxuck me!

here is my solution:

  1. brew update
  2. brew upgrade watchman -> 2022.12.26
  3. xcode run my rn project -> fail
  4. sudo tccutil reset XXX
  5. brew uninstall watchman
  6. brew install watchman
  7. restart mac -> when you start mac, watchman will ask access to file&foler, YES
  8. restart rn project -> SUCCESS

Click on the Apple Icon and open System preferences -> Click on Security & Privacy -> File & Folders -> check Watchman

After following the post by @cktaylor and getting off 6.20 my issue was resolved

So just to be clear, you’re saying that 2022.06.27.00 is working for you (where previous versions had the error described in the OP)? What chip tech and OS?

Sorry! Yes - 06.27 was the version I updated to that resolved this issue for me after uninstalling watchman 06.20. I also did the suggested check and ran the shutdown server command and to my surprise even after uninstalling watchman, 06.20 was still running on my machine. My workspace is a MacBook Pro M1 running Monterey 12.0.1.

2022.06.27.00 indeed does fix the issue for the repo on the external drive on my system (Apple Silicon/macOS 12.4).

I’m still getting a Operation not permitted on version 2022.06.20.00. My app is on an External HDD.

Update: It does work if I move the files to my local HDD.

I’ve done the above solution to revert to a working version, but it seems incompatible with another tool, folly which is at a later version. Any fix there? @robert-go seemed to be having the same issue above.

Downgrade to Version 2022.05.16 work for me. (Mac OS Monterey 12.4 - Intel Chip)

watchman watch-del-all watchman shutdown-server brew unpin watchman brew uninstall watchman

curl https://raw.githubusercontent.com/Homebrew/homebrew-core/8651d8e23d308e564414188509f864e40548f514/Formula/watchman.rb > /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/watchman.rb

brew install watchman brew pin watchman cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/ git checkout -- watchman.rb

And restart your mac. and run

watchman version It is should be 2022.05.16.00

If you still get error … run metro at least twice times and check watchman version that showed in Error Log. I hope this help.

I hope watchman team will fix this soon.

@musasoftlabx Thanks for the explaination.

I’m running on Intel, with Monterrey.

I think thoses permissions does affect my projects setup not only reactnative. I have been experiencing problems with sockets on mariadb since I upgraded macos, brew.

@robert-go try adding “sh” permissions to the disk

What is the file location for sh? (I’m on mac btw)

which sh

/bin/sh

The workaround worked around initially but it’s broken again and now I’m getting different error.

app/node_modules/metro-hermes-compiler/src/emhermesc.js:77
          throw ex;
          ^

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:204:21)
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.checkedEmitError (app/node_modules/sane/src/node_watcher.js:143:12)
    at FSWatcher.emit (node:events:527:28)
    at FSEvent.FSWatcher._handle.onchange (node:internal/fs/watchers:210:12) {
  errno: -24,
  syscall: 'watch',
  code: 'EMFILE',
  filename: null
}
error Command failed with exit code 7.

And I also get this error trying to run any watchman command directly:

watchman shutdown-server                                                                                               
dyld[82779]: Symbol not found: __ZN5folly19shared_mutex_detail25getMaxDeferredReadersSlowERNSt3__16atomicIjEE
  Referenced from: /opt/homebrew/Cellar/watchman/2022.05.16.00/bin/watchman
  Expected in: /opt/homebrew/Cellar/folly/2022.06.06.00/lib/libfolly.0.58.0-dev.dylib
[1]    82779 abort      watchman shutdown-server

And I did run brew upgrade multiple times since the workaround steps. Maybe we need pin more than just watchman itself.

Can someone explain why the last step git checkout – watchman.rb is required?

It is to reset the change you just made by replacing watchman.rb with a previous version. Brew update will break if you have un-committed changes.

guys,you need reinstall “version”: “2022.05.16.00”.

I tried that both using the ZIP (which doesn’t work at all #1031) and using previous Hombrew formulas, none of which produced a functioning installation. How did you manage to install a previous version?