React Native打包器启动异常求助:npm start后打包器无限启动
Hey there, sorry to hear you're stuck with the Metro bundler hanging indefinitely when running npm start—let’s walk through some common fixes that usually resolve this, especially for folks new to React Native following the official docs!
Here are the steps to try, in order of how likely they are to solve your problem:
Reset Metro's cache
Cached files are the #1 culprit for this kind of hang. Run this command instead of plainnpm start:npm start -- --reset-cacheIf that doesn’t work, you can manually delete the Metro cache directory:
- On Mac/Linux:
rm -rf ~/.metro-cache - On Windows: Delete the folder at
%USERPROFILE%/.metro-cache
- On Mac/Linux:
Verify your Node.js version
React Native requires specific Node versions (usually the latest LTS release). Check your current version with:node -vIf it’s not matching the version specified in React Native’s official setup docs, consider using a version manager like
nvm(for Mac/Linux) ornvm-windowsto switch to a compatible version.Reinstall dependencies
Sometimes partial or corrupted installs cause issues. Delete yournode_modulesfolder and lock file, then reinstall:rm -rf node_modules package-lock.json # On Windows, use rmdir /s node_modules and del package-lock.json npm installCheck for port conflicts
Metro uses port 8081 by default. If another app is using this port, the bundler can’t start properly.- Mac/Linux: Check what’s using port 8081 with
lsof -i :8081, then kill the process withkill -9 <PID>(replace<PID>with the number from the output). - Windows: Run
netstat -ano | findstr :8081to find the PID, then open Task Manager to end that process.
Alternatively, start Metro on a different port:
npm start -- --port 8082- Mac/Linux: Check what’s using port 8081 with
Disable firewall/proxy temporarily
Local firewalls or proxy settings can block Metro from connecting. Try turning them off briefly to see if the bundler starts—if it does, you’ll need to add an exception for Metro or adjust your proxy settings.Double-check environment setup
Make sure you’ve completed all steps from the official setup docs:- For Android: Verify
ANDROID_HOMEandJAVA_HOMEenvironment variables are set correctly, and you’ve installed all required SDK components. - For iOS: Ensure Xcode is up to date and you’ve installed the command-line tools (
xcode-select --install).
- For Android: Verify
Try these steps one by one, and I bet one of them will get your bundler running smoothly!
内容的提问来源于stack exchange,提问作者E.Belekov

