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

使用npx命令创建React应用失败,遇ENOENT错误求解决

解决npx create-react-app报错ENOENT的方案

PS C:\Users\bidar\Downloads\React> npx create-react-app my-app
npm error code ENOENT
npm error syscall lstat
npm error path C:\Users\bidar\AppData\Roaming\npm
npm error errno -4058
npm error enoent ENOENT: no such file or directory, lstat 'C:\Users\bidar\AppData\Roaming\npm'
npm error enoent This is related to npm not being able to find a file.
npm error enoent

解决方案

1. 手动创建缺失的npm目录

  • 打开文件资源管理器,进入C:\Users\bidar\AppData\Roaming路径
  • 新建名为npm的文件夹
  • 或者直接在PowerShell中执行命令创建:
mkdir C:\Users\bidar\AppData\Roaming\npm

2. 重新配置npm全局路径

执行以下命令确保npm的全局前缀指向正确路径:

npm config set prefix "C:\Users\bidar\AppData\Roaming\npm"

同时检查缓存路径是否存在,执行npm config get cache,如果返回的路径不存在,同样手动创建该目录。

3. 以管理员身份运行终端重试

右键点击PowerShell或VSCode,选择「以管理员身份运行」,然后重新执行创建命令:

npx create-react-app my-app

4. 检查并配置环境变量

  • 按下Win + R,输入sysdm.cpl打开系统属性窗口
  • 切换到「高级」标签页,点击「环境变量」
  • 在用户变量的Path中,检查是否包含C:\Users\bidar\AppData\Roaming\npm,如果没有则添加该路径
  • 重启所有终端窗口后重试命令

内容的提问来源于stack exchange,提问作者Achutha Bidarahalli

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 10:43:14