Node 8.10+npm4环境下React Native项目启动失败求助
Hey there, I’ve dealt with this exact problem when setting up React Native on macOS with Node 8.10 and npm 4, so let’s get your project running smoothly again.
First, Resolve the File Descriptor Limit
The error message points directly to a system file limit issue—React Native and its tooling need to open a lot of files during development, and macOS’s default limits are too low for this.
Temporary fix (works until reboot): Run these two commands in your terminal:
sudo sysctl -w kern.maxfiles=5242880 sudo sysctl -w kern.maxfilesperproc=524288Permanent fix (so you don’t have to re-run this after every restart):
- Create and edit the system sysctl config file:
sudo nano /etc/sysctl.conf - Paste these two lines into the file:
kern.maxfiles=5242880 kern.maxfilesperproc=524288 - Save and exit: Press
Ctrl+O, hit Enter, thenCtrl+X. - Load the new config immediately without rebooting:
sudo sysctl -p
- Create and edit the system sysctl config file:
Install Watchman (Recommended Long-Term Solution)
Watchman is a tool from Facebook that helps React Native efficiently monitor file changes, and it avoids hitting system file limits entirely. Here’s how to install it:
- If you use Homebrew (the easiest package manager for macOS), run:
brew install watchman - If you don’t have Homebrew, you can compile it from source, but Homebrew is the quickest route for most users.
Clean Up and Restart Your Project
After fixing the limits or installing Watchman, let’s reset your project to ensure no cached issues are left:
- Navigate back to your project directory:
cd AwesomeProject - Clear npm cache and reinstall dependencies:
npm cache clean --force rm -rf node_modules npm install - Start the project again:
npm start
This should resolve the ELIFECYCLE error and get your React Native dev server up and running.
内容的提问来源于stack exchange,提问作者xduris

