Windows环境下使用npx创建React App失败求助
React应用创建失败(spawn UNKNOWN/EBUSY错误)解决方案
问题概述
已安装Node.js 18.9.0版本,执行npx create-react-app my-app-one创建React应用时持续失败,触发spawn UNKNOWN错误。后续尝试更新tar、升级npm至8.19.2、以管理员模式运行命令提示符、更换磁盘路径、多次重装Node.js并重启电脑,改用Yarn工具后仍遇到EBUSY等错误,无法成功创建应用。
相关报错信息
初始npx报错
C:\Users\MyName\Documents\React>npx create-react-app my-app-one Need to install the following packages: create-react-app@5.0.1 Ok to proceed? (y) y npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap. Creating a new React app in C:\Users\MyName\Documents\React\my-app-one. Installing packages. This might take a couple of minutes. Installing react, react-dom, and react-scripts with cra-template... Aborting installation. Unexpected error. Please report it as a bug: Error: spawn UNKNOWN at ChildProcess.spawn (node:internal/child_process:413:11) at Object.spawn (node:child_process:743:9) at spawn (C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\cross-spawn\index.js:12:24) at C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\create-react-app\createReactApp.js:383:19 at new Promise (<anonymous>) at install (C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\create-react-app\createReactApp.js:334:10) at C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\create-react-app\createReactApp.js:461:16 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { errno: -4094, code: 'UNKNOWN', syscall: 'spawn' } Deleting generated file... package.json Deleting my-app-one/ from C:\Users\MyName\Documents\React Done. npm notice npm notice New patch version of npm available! 8.19.1 -> 8.19.2 npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.19.2 npm notice Run npm install -g npm@8.19.2 to update! npm notice
修复后npx报错
C:\Users\MyName\Documents\React>npx create-react-app app-xyz Creating a new React app in C:\Users\MyName\Documents\React\app-xyz. Installing packages. This might take a couple of minutes. Installing react, react-dom, and react-scripts with cra-template... Aborting installation. npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed. Deleting generated file... package.json Deleting app-xyz/ from C:\Users\MyName\Documents\React node:fs:1225 return handleErrorFromBinding(ctx); ^ Error: EBUSY: resource busy or locked, rmdir '\\?\C:\Users\MyName\Documents\React\app-xyz' at rmdirSync (node:fs:1225:10) at _rmdirSync (node:internal/fs/rimraf:235:5) at rimrafSync (node:internal/fs/rimraf:193:7) at Object.rmSync (node:fs:1274:10) at Object.removeSync (C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\fs-extra\lib\remove\index.js:15:28) at C:\Users\MyName\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\create-react-app\createReactApp.js:539:14 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { errno: -4082, syscall: 'rmdir', code: 'EBUSY', path: '\\\\?\\C:\\Users\\MyName\\Documents\\React\\app-xyz' } Node.js v18.9.0
Yarn报错
C:\Users\MyName\Desktop\Apps>yarn create react-app my-app yarn create v1.22.19 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... success Installed "create-react-app@5.0.1" with binaries: - create-react-app Creating a new React app in C:\Users\MyName\Desktop\Apps\my-app. Installing packages. This might take a couple of minutes. Installing react, react-dom, and react-scripts with cra-template... Aborting installation. yarnpkg add --exact react react-dom react-scripts cra-template --cwd C:\Users\MyName\Desktop\Apps\my-app has failed. Deleting generated file... package.json Deleting my-app/ from C:\Users\MyName\Desktop\Apps Done. error Command failed. Exit code: 1 Command: C:\Users\MyName\AppData\Local\Yarn\bin\create-react-app Arguments: my-app Directory: C:\Users\MyName\Desktop\Apps Output: info Visit https://yarnpkg.com/en/docs/cli/create for documentation about this command.
解决方案
1. 清理Node.js缓存
- 执行命令清理npm缓存:
npm cache clean --force - 若使用Yarn,执行:
yarn cache clean - 手动删除npm缓存目录:
C:\Users\MyName\AppData\Local\npm-cache,以及Yarn缓存目录(若使用)
2. 临时禁用安全软件拦截
- 关闭Windows Defender实时保护、第三方杀毒软件,避免它们拦截Node.js的文件操作或子进程创建
- 关闭后重新尝试创建应用命令
3. 修改Node.js执行权限
- 打开管理员模式命令提示符,执行以下命令(替换为你的Node.js实际安装路径):
icacls "C:\Program Files\nodejs\node.exe" /grant Everyone:F /T
4. 手动创建React应用(绕过create-react-app)
- 手动初始化项目:
mkdir my-app cd my-app npm init -y - 手动安装核心依赖:
npm install react react-dom react-scripts cra-template --save-exact - 在
package.json中添加脚本:"scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" } - 复制cra-template模板文件:从
C:\Users\MyName\AppData\Local\npm-cache\_npx\*\node_modules\cra-template\template目录复制所有文件到项目根目录
5. 降级Node.js版本
- 卸载当前Node.js 18.9.0,安装稳定LTS版本(如16.x或18.x最新LTS版本)
- 安装完成后重启电脑,再尝试创建应用
6. 检查目录状态与权限
- 确保创建应用的目录未被其他程序占用(如文件资源管理器打开目录、编辑器监控目录)
- 尝试在非系统盘(如D盘)创建应用,规避系统目录权限限制
内容的提问来源于stack exchange,提问作者Janz
相关产品推荐
相关产品推荐

