升级系统后React Native运行Metro报Watchman爬取失败无法添加访问权限
问题场景
升级操作系统后启动React Native Metro服务时抛出异常,核心报错如下:
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: std::__1::system_error: open: /Users/dongjae/Desktop/wellCupOfficial/wellcupOfficial/wellcupApp: Operation not permitted. Make sure watchman is running for this project. /Users/dongjae/Desktop/wellCupOfficial/wellcupOfficial/wellcupApp/node_modules/metro-hermes-compiler/src/emhermesc.js:77 throw ex;
已排查确认修复方向为将watchman加入系统「安全性与隐私」的「完全磁盘访问权限」列表,但本地watchman安装路径为/opt/local/bin/watchman,权限配置的文件选择窗口默认隐藏/opt目录,无法选中目标程序完成授权。
解决方法
以下方法任选其一即可完成权限配置:
- 快捷键直接定位隐藏路径
- 打开系统设置的「安全性与隐私」-「完全磁盘访问权限」页,点击左下角锁图标输入密码解锁配置,点击+号唤起文件选择窗口
- 保持文件选择窗口为当前激活窗口,按下
Command + Shift + G唤起路径直达输入框 - 输入watchman完整路径
/opt/local/bin/watchman后按回车,会自动定位到目标程序,点击「打开」即可完成添加
- 软链接中转选择
如果快捷键定位路径失效,可以先在终端执行命令创建软链接:sudo ln -s /opt/local/bin/watchman /Applications/watchman,之后在文件选择窗口直接进入应用程序目录,就能看到watchman的入口,选中添加即可,授权完成后可执行rm /Applications/watchman删除临时软链接 - 命令行直接写入权限
不想手动点选配置的话,可以直接在终端执行以下命令完成授权:watchman shutdown-server sudo sqlite3 ~/Library/Application\ Support/com.apple.TCC/TCC.db "INSERT or REPLACE INTO access VALUES('kTCCServiceSystemPolicyAllFiles','/opt/local/bin/watchman',0,1,1,NULL,NULL,NULL,'UNUSED',NULL,0,NULL);"
生效验证
权限添加完成后,执行watchman shutdown-server关闭已运行的watchman进程,再重新启动Metro服务即可正常运行,不会再抛出Operation not permitted的错误。
内容的提问来源于stack exchange,提问作者Dongjae0324
相关产品推荐
相关产品推荐

