You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode终端执行npx create-react-app时未在指定目录创建React项目

Fix: npx create-react-app Creates Project in Root Drive Instead of Target Directory

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 appname and 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 21:43:01