Node与React启动服务器遇ELIFECYCLE错误,求技术解决方案
Hey there! I’ve run into this exact issue before when setting up React Native on Linux—let’s get your server up and running smoothly. The error log clearly points to a file watching limit problem with your system’s inotify service, which React Native uses to track code changes. Here are two solid solutions:
Quick Temporary Fix
First, let’s apply the immediate fix suggested in the error message. Run these two commands in your terminal to bump up the inotify limits:
sudo sysctl -w fs.inotify.max_user_instances=1024 sudo sysctl -w fs.inotify.max_user_watches=12288
Once you’ve run those, try starting your server again with:
npm start
This should work right away, but note that these changes will reset when you restart your computer.
Permanent Fix (Recommended)
To make these limits stick even after a reboot, add them to your system’s sysctl configuration:
- Open the sysctl config file with a text editor (I’ll use nano here):
sudo nano /etc/sysctl.conf - Add these two lines at the bottom of the file:
fs.inotify.max_user_instances=1024 fs.inotify.max_user_watches=12288 - Save the file (press
Ctrl+O, thenEnter, thenCtrl+Xto exit nano) - Apply the changes immediately with:
sudo sysctl -p
Alternative: Install Watchman
If you want a more robust file watching solution (recommended for long-term React Native development), install Watchman—Facebook’s dedicated tool for this purpose:
- First install the required build dependencies:
sudo apt-get install -y autoconf automake build-essential python3-dev - Grab the latest stable release of Watchman, extract it, and navigate into the extracted directory.
- Run these commands to compile and install it:
./autogen.sh && ./configure && make && sudo make install - Verify the installation worked:
watchman --version
After installing Watchman, restart your React Native server—it should start without issues.
Since you’re new to React Native, just a quick note: make sure your Node.js version matches the requirements listed in your project’s package.json (check the engines field if it exists) to avoid other potential hiccups down the line.
内容的提问来源于stack exchange,提问作者Joshua Blevins

