执行npx create-react-app时遭遇ENOENT错误求助
解决npx create-react-app时出现“spawn C:\WINDOWS\system32\cmd.exe ENOENT”错误
执行命令npx create-react-app my-react-app时出现如下错误:
PS C:\Users\ARPIT\Desktop> npx create-react-app my-react-app npm error code ENOENT npm error syscall spawn C:\WINDOWS\system32\cmd.exe npm error path C:\Users\ARPIT\Desktop npm error errno -4058 npm error enoent spawn C:\WINDOWS\system32\cmd.exe ENOENT npm error enoent This is related to npm not being able to find a file. npm error enoent npm error A complete log of this run can be found in: C:\Users\ARPIT\AppData\Local\npm-cache\_logs\2024-07-18T09_45_44_534Z-debug-0.log
已尝试修改环境变量、重装Node.js两次仍未解决,可尝试以下方案:
- 检查系统Path环境变量
右键「此电脑」→属性→高级系统设置→环境变量,在系统变量的Path列表中确认包含C:\WINDOWS\system32,若缺失则添加,之后重启终端和电脑。 - 验证cmd.exe是否存在
打开文件管理器导航到C:\WINDOWS\system32,确认cmd.exe文件存在。若文件丢失,以管理员身份打开CMD,运行sfc /scannow扫描并修复系统文件。 - 以管理员权限运行终端
右键PowerShell或CMD,选择「以管理员身份运行」,再次执行npx create-react-app my-react-app。 - 清理npm缓存并指定shell
依次执行以下命令:npm cache clean --force npx create-react-app my-react-app --shell cmd.exe - 检查Node.js安装目录权限
找到Node.js安装目录(默认C:\Program Files\nodejs),右键→属性→安全,确认当前用户拥有「完全控制」权限,若没有则添加对应权限。
内容的提问来源于stack exchange,提问作者Arpit Dhuriya
相关产品推荐
相关产品推荐

