无法正常安装React求助:执行npx create-react-app时出现ENOENT错误
React项目创建失败(ENOENT错误)解决方案
问题描述
执行npx create-react-app employee_app创建React项目时出现以下错误:
C\Windows\System32\cmd.e X + Microsoft Windows [Version 10.0.22621.2715] (c) Microsoft Corporation. All rights reserved. C:\Users\user\Desktop\React>npx create-react-app employee_app npm ERR! code ENOENT npm ERR! syscall Istat npm ERR! path C:\Users\user\AppData\Roaming\npm npm ERR! errno -4058 npm ERR! enoent ENOENT: no such file or directory, Istat 'C:\Users\user\A ata\Roaming\npm' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent npm ERR! A complete log of this run can be found in: C:\Users\user\AppData ocal\npm-cache_logs\2023-12-22T17_12_07_950Z-debug-0.log C:\Users\user\Desktop\React>
已确认Node.js和npm为最新版本,但无法完成安装。
解决步骤
检查并创建缺失目录
- 打开文件资源管理器,开启「显示隐藏项目」选项(在「查看」菜单中)
- 导航到
C:\Users\user\AppData\Roaming路径 - 若该路径下无
npm文件夹,手动创建一个
重置npm配置
- 以管理员身份启动命令提示符(CMD)
- 执行命令:
npm config set prefix "C:\Users\user\AppData\Roaming\npm" - 清理npm缓存:
npm cache clean --force
重新创建项目
返回目标目录,再次执行npx create-react-app employee_app。若仍失败,可尝试使用Vite替代:npm init vite@latest employee_app -- --template react
内容的提问来源于stack exchange,提问作者Subin k k
相关产品推荐
相关产品推荐

