为什么在更新到 macOS catalina 后立即在 react-native 中出现“Watchman crawl failed”错误?

Jim*_*Jim 6 terminal watchman react-native react-native-android react-native-ios

尝试react-native run-ios从 xcode运行或构建 RN 项目,一旦 Metro bundler 启动,终端中就会出现此错误:

Loading dependency graph...jest-haste-map: Watchman crawl failed. Retrying once with node crawler.
  Usually this happens when watchman isn't running. Create an empty `.watchmanconfig` file in your project's root folder or initialize a git or hg repository in your project.
  Error: Watchman error: resolve_projpath: path `/Users/vorousjames/Desktop/Development/TicTacWHOA/app/TicTacWHOA`: open: /Users/vorousjames/Desktop/Development/TicTacWHOA/app/TicTacWHOA: Operation not permitted. Make sure watchman is running for this project. See https://facebook.github.io/watchman/docs/troubleshooting.html.
events.js:183
      throw er; // Unhandled 'error' event
  ^

Error: resolve_projpath: path `/Users/vorousjames/Desktop/Development/TicTacWHOA/app/TicTacWHOA`: open: /Users/vorousjames/Desktop/Development/TicTacWHOA/app/TicTacWHOA: Operation not permitted
    at BunserBuf.<anonymous> (/Users/vorousjames/Desktop/Development/TicTacWHOA/app/TicTacWHOA/node_modules/fb-watchman/index.js:95:23)
    at emitOne (events.js:116:13)
    at BunserBuf.emit (events.js:211:7)
    at BunserBuf.process (/Users/vorousjames/Desktop/Development/TicTacWHOA/app/TicTacWHOA/node_modules/bser/index.js:292:10)
    at /Users/vorousjames/Desktop/Development/TicTacWHOA/app/TicTacWHOA/node_modules/bser/index.js:247:12
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
Run Code Online (Sandbox Code Playgroud)

这在 Catalina 更新之前从未发生过。从一开始,我的项目根目录中就有一个空的 watchman 配置文件。在第一次启动后更新时,终端中有一个弹出窗口,说一些关于权限的内容,但我不记得了。我的终端在 Visual Studio 代码中也有一条通知,说“默认 shell 更改为 zsh”运行chsh -s /bin/zsh更改,所以我做了。

我试过了:

  • watchman watch-del-all

  • watchman server-shutdown

  • 从系统首选项-> 隐私选项卡中添加对终端的完整磁盘访问

  • npm uninstall watchman & npm uninstall -g watchman

Jub*_*ali 38

您需要授予对 的磁盘访问权限watchman。为此,您需要:

  • 转到System preferences>Security & Privacy然后向下滚动
  • 选择Full Disk Access
  • 解锁并单击+按钮添加新的应用程序/工具
  • Macintosh HD在文件夹列表中选择
  • shift Command .同时按下该组合键可查看所有目录列表
  • 单击opt > brew > bin(对于 MacOS Catalina,watchman 安装在该文件夹中)|| usr > local > Cellar > Watchman > 21***** > bin(watchman安装在MacOS Monterey这个文件夹中)
  • watchman在列表中查找然后选择它

来吧,这应该可以解决问题。

  • 升级到 Mac OS Monterey 后我遇到了同样的问题,这为我解决了这个问题,除了我的守望者位于 usr/local/Cellar 中 (6认同)
  • 执行这些步骤后,可能需要重新启动 watchman 服务(“watchman shutdown-server”,然后“watchman”)才能生效。还可以考虑使用“watchman watch-del-all”清除其缓存,或者如果不起作用的话打开一个新的终端窗口。 (3认同)
  • 所以看来 v2022.05.30.00 已损坏。请参阅:[此处](https://github.com/facebook/watchman/issues/1030) (2认同)

小智 32

先运行watchman watch-del-all 然后运行watchman shutdown-server解决了我的问题


小智 14

更新到 Catalina 后,我遇到了同样的问题。Wez Furlong 的回答对我有用,但我必须提供对 watchman 的完整磁盘访问权限才能运行 watchman watch-project 命令而不会出现“不允许操作”错误。作为先前故障排除的一部分,我还提供了对 Xcode 和终端的完整磁盘访问(不确定这是否也有助于修复)。

在此处输入图片说明

  • 如果 Watchman 不在该应用程序列表中该怎么办? (6认同)

d36*_*ams 12

要更改 Watchman 对 Documents 文件夹的权限,它位于系统首选项中的安全和隐私 -> 文件和文件夹下

通过在 Document 文件夹下的列表中检查 Watchman 解决了我的问题