使用Jest执行npm test时遇Watchman报错,求解决方案
Hey there, let’s work through this frustrating issue with Jest and Watchman. The error you’re seeing points to a messed-up Watchman configuration file path—specifically, the system thinks com.github.facebook.watchman.plist is a directory instead of a file, which breaks Watchman (and in turn, Jest).
Here’s a step-by-step fix:
- Check the problematic path
First, let’s confirm what’s actually in that LaunchAgents directory:
ls -la /Users/abhimanyuaryan/Library/LaunchAgents/
Look for com.github.facebook.watchman.plist—if you see it listed as a directory (marked with d at the start of the line), that’s the root cause.
- Remove the incorrect directory
If it is a directory, delete it safely:
rm -rf /Users/abhimanyuaryan/Library/LaunchAgents/com.github.facebook.watchman.plist
Double-check you’re deleting the right thing—this shouldn’t affect any critical system files, just the messed-up Watchman entry.
- Reset or reinstall Watchman
Next, let’s fix Watchman itself. If you installed it via Homebrew, you can fully reinstall it:
brew uninstall watchman brew install watchman
Or if you prefer not to reinstall, reset Watchman’s state instead:
watchman watch-del-all watchman shutdown-server
- Test again with Jest
Run your test command once more:
npm test
Temporary workaround (if you need to test immediately)
If you just need to get tests running without fixing Watchman right now, you can disable Watchman in Jest:
- Add this to your
jest.config.js:
module.exports = { watchman: false, };
Or run Jest directly with the flag:
jest --watchman false
内容的提问来源于stack exchange,提问作者abhimanyuaryan

