运行npx create-react-app出现ENOENT错误,请求解决方案
解决
npx create-react-app my-app执行时的ENOENT错误 问题详情
执行命令:
npx create-react-app my-app
遇到以下错误:
npm ERR! code ENOENT npm ERR! syscall lstat npm ERR! path C:\Users\dejean\AppData\Roaming\npm npm ERR! errno -4058 npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\Users\dejean\AppData\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: npm ERR! C:\Users\dejean\AppData\Local\npm-cache\_logs\2023-06-27T18_53_22_682Z-debug-0.log
当前环境:Node.js 18.16.1,npm 9.5.1
解决方案
手动创建缺失的npm目录
打开CMD(普通用户身份即可),执行命令创建目录:mkdir "C:\Users\dejean\AppData\Roaming\npm"重新全局安装npm
执行命令修复npm安装结构:npm install -g npm清理缓存后重试创建项目
先清理npm缓存:npm cache clean --force之后再次运行创建命令:
npx create-react-app my-app检查并配置环境变量
- 右键「此电脑」→「属性」→「高级系统设置」→「环境变量」
- 在「用户变量」的
Path中,确认是否包含C:\Users\dejean\AppData\Roaming\npm,无则添加该路径 - 保存后重启命令提示符再尝试操作
内容的提问来源于stack exchange,提问作者H-Bar
相关产品推荐
相关产品推荐

