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

使用npx create-react-app创建React项目遇EPERM权限错误,求解决方案

问题描述

在VS Code终端执行以下命令:

npx create-react-app my-app

出现如下错误:

PS E:\react> npx create-react-app my-app
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path C:\Users\username~1\AppData\Roaming\npm-cache\_cacache\tmp\07cf48de
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, open 'C:\Users\username~1\AppData\Roaming\npm-cache\_cacache\tmp\07cf48de'
npm ERR!  [Error: EPERM: operation not permitted, open 'C:\Users\username~1\AppData\Roaming\npm-cache\_cacache\tmp\07cf48de'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'open',
npm ERR!   path: 'C:\\Users\\Nabanita~1\\AppData\\Roaming\\npm-cache\\_cacache\\tmp\\07cf48de'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! Log files were not written due to an error writing to the directory: C:\Users\username~1\AppData\Roaming\npm-cache\_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
PS E:\react>

已尝试以下命令,但问题未解决:

npm install -g create-react-app    
npx create-react-app my-app     
cd my-app       
npm start 
解决方案
  • 以管理员身份运行VS Code
    右键VS Code图标,选择「以管理员身份运行」,再重新执行npx create-react-app my-app命令。
  • 清理npm缓存
    执行以下命令清理缓存,避免缓存文件权限冲突:
    npm cache clean --force
    
    清理完成后再次尝试创建React项目。
  • 检查杀毒软件或文件占用
    暂时关闭杀毒软件(如Windows Defender、360安全卫士等),确认没有其他程序(如文本编辑器、资源管理器)正在访问C:\Users\你的用户名\AppData\Roaming\npm-cache目录,然后重新执行命令。
  • 修改npm缓存目录权限
    找到C:\Users\你的用户名\AppData\Roaming\npm-cache目录,右键选择「属性」→「安全」→「编辑」,给当前用户添加「完全控制」权限,应用后重新尝试。
  • 更换npm镜像源
    执行以下命令切换到国内镜像:
    npm config set registry https://registry.npmmirror.com
    
    之后再执行npx create-react-app my-app。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 00:22:38