执行sudo npm start返回错误代码11及FSEvents相关报错求助
npm start on Mac Hey there, let's work through this frustrating FSEvents error you're facing when starting your React project. That register_with_server: ERROR: f2d_register_rpc() => (null) (-22) message usually ties into permission issues, stuck system processes, or outdated tools. Here are some practical fixes to get things back on track:
Ditch
sudofor npm commands first
Runningsudo npm startmesses with file ownership and can throw off system services like FSEvents. Let's fix your npm permissions so you don't need root access:- Find where npm is installed:
which npm - Take ownership of the global npm directory:
sudo chown -R $(whoami) $(npm prefix -g) - Now run
npm startwithoutsudo—this alone fixes the issue for most people.
- Find where npm is installed:
Restart the FSEvents daemon
Sometimes the FSEvents service gets stuck. Try killing and restarting it:sudo killall -KILL fseventsdIf that doesn't do the trick, a full restart of your Mac often clears up stuck system processes.
Clear cache and reinstall dependencies
Corrupted cache or node modules can cause weird conflicts. Let's reset them:- Clear the npm cache:
npm cache clean --force - Delete your
node_modulesfolder and lock file:rm -rf node_modules package-lock.json - Reinstall dependencies:
npm install - Try starting the project again with
npm start
- Clear the npm cache:
Update Node.js and npm to stable versions
Outdated Node/npm versions might not play nice with newer macOS FSEvents. Use a version manager like nvm for easy updates (it also avoids permission headaches):nvm install stable nvm use stableIf you don't use nvm, you can download the latest installer directly from Node.js' website.
Temporarily use polling instead of FSEvents
If all else fails, you can bypass FSEvents entirely (note: this reduces hot reloading efficiency but works as a quick fix):CHOKIDAR_USEPOLLING=true npm startCheck for macOS updates
Outdated macOS versions can have bugs with system frameworks like FSEvents. Head to System Settings > General > Software Update and install any available updates.
内容的提问来源于stack exchange,提问作者Code Hunter

