VSCode终端执行npx create-react-app时未在指定目录创建React项目
Hey there, let's troubleshoot why your React project is ending up in the root drive instead of the directory you intended—this is a super common gotcha with VS Code's integrated terminal!
First, Check Your Terminal's Current Working Directory
The most likely culprit is that your VS Code terminal isn't pointed at the folder you want to use. Here's how to confirm:
- Look at the start of your terminal prompt (e.g.,
C:\Users\YourName\>or~/). If this path doesn't match your target project folder, that's the problem.
Fix 1: Manually Switch to Your Target Directory
Run the cd command to navigate to your desired folder before creating the React app:
- For Windows:
cd C:\Path\To\Your\Target\Folder npx create-react-app appname - For Mac/Linux:
cd /path/to/your/target/folder npx create-react-app appname
Fix 2: Open Terminal Directly from Your Target Folder (Easier!)
Skip the manual directory change entirely:
- In VS Code's left sidebar (Explorer), navigate to your target folder.
- Right-click the folder and select "Open in Integrated Terminal".
- Now your terminal will automatically be set to this folder—just run
npx create-react-app appnameand the project will land right where you want it.
Quick Note to Avoid Future Headaches
Always double-check the terminal's current path before running project creation commands. If you open VS Code without opening a specific folder first, the terminal defaults to your user directory (or root drive in some cases) instead of your intended project location.
内容的提问来源于stack exchange,提问作者Akshay Ashok

