Mac下React Native执行npm install失败,求助原因及解决办法
Hey there! I’ve seen this exact graceful-fs issue pop up a lot with new React Native devs—let’s walk through some concrete fixes to get you up and running:
Step 1: Nuke Corrupted npm Cache
First up, npm’s cache is often the culprit here. Corrupted cache entries can make npm think packages are missing even when they exist. Run this command to wipe it clean:
npm cache clean --force
Step 2: Reset Your Project Dependencies
Your local node_modules folder or lock file might have a broken dependency tree. Let’s start fresh:
- Delete the entire
node_modulesfolder:rm -rf node_modules - Delete your
package-lock.jsonfile (if you’re using npm):rm package-lock.json
Step 3: Reinstall graceful-fs Directly
Sometimes npm needs a little nudge to grab the correct version of graceful-fs. Install it explicitly first, then reinstall all dependencies:
npm install graceful-fs@latest --save npm install
Step 4: Check Global npm Packages
Since you installed react-native-cli globally, there might be a broken graceful-fs instance in your global npm space too. Let’s fix that:
- First, check if global
graceful-fsis messed up:npm ls -g graceful-fs - If you see errors, reinstall it globally:
npm install -g graceful-fs@latest
Step 5: Reset Watchman (Just in Case)
You mentioned you installed Watchman—sometimes its internal cache can interfere with npm’s operations. Reset it with:
watchman watch-del-all && watchman shutdown-server
Final Check
After running all these steps, try starting your React Native project again:
npm start
If you still hit issues, double-check that your Node.js version matches React Native’s recommended LTS version (avoid bleeding-edge releases—they can cause compatibility hiccups).
内容的提问来源于stack exchange,提问作者GʀᴜᴍᴘʏCᴀᴛ

