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

npx执行后批处理脚本终止?React项目初始化脚本问题求助

解决React初始化批处理脚本中断问题

在Windows批处理环境中,直接执行npx或npm这类命令时,它们会接管当前的批处理进程,导致脚本在执行完这些命令后直接终止,后续步骤无法运行。要让脚本完整执行所有步骤,只需在这类外部命令前添加call指令,让命令在子进程中执行,执行完成后回到原批处理继续后续操作。

修改后的完整脚本如下:

@echo off

set /p userInput=Enter the folder name for your new React app: 
mkdir %userInput%
cd %userInput%

call npx create-react-app . --template cra-template-pwa
call npm install -D tailwindcss
call npx tailwindcss init

echo.
echo Finished setting up React environment
pause

这样修改后,脚本会依次完成所有步骤,直到最后暂停等待用户操作。

内容的提问来源于stack exchange,提问作者Cardinal System

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 18:27:31