React Native项目初始化失败问题求助
Hey there, let's fix this issue step by step. The core problem here is that your Yarn local cache has a corrupted copy of the @react-native-community/cli package, and you're hitting Windows permission restrictions when trying to access that file. Reinstalling the global CLI won't help because it's not the global tool that's broken—it's the cached package Yarn keeps locally.
Here's what you need to do:
1. Force-clean Yarn's cache
First, we need to get rid of that corrupted package in Yarn's cache. Run this command in your terminal:
yarn cache clean --force
This will delete all cached packages, so Yarn has to download fresh copies next time.
2. Fix permission issues on Windows
The EPERM error means your user account doesn't have the right permissions to access or modify the cache files. Try these:
- Close all related apps: Make sure VS Code, any open terminals, or Node.js processes are closed—they might be locking the cache files.
- Run terminal as Administrator: Right-click your terminal (Command Prompt/PowerShell) and select "Run as administrator". This gives you the elevated permissions needed to modify system-level cache directories.
3. Re-initialize your React Native project
Now that the cache is clean and you have proper permissions, try initializing the project again:
react-native init TravelApp
4. Fallback: Use NPM instead of Yarn
If Yarn still gives you trouble, you can bypass it entirely by telling React Native to use NPM for dependencies:
react-native init TravelApp --npm
5. Optional: Refresh your global CLI (just to be safe)
Even though this wasn't the root issue, you can refresh the global CLI to ensure there's no leftover cruft:
npm uninstall -g react-native-cli npm install -g react-native-cli
Quick checks to avoid future issues
- Make sure you're using an LTS version of Node.js (like 16.x or 18.x)—newer versions can sometimes cause compatibility issues with older React Native CLI versions.
- Verify that your user account has read/write permissions for the
C:\Users\sushant.patekar\AppData\Local\Yarndirectory. You can right-click the folder, go to Properties > Security, and ensure your user has full control.
That should get your project up and running!
内容的提问来源于stack exchange,提问作者Sushant Patekar

