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

执行npx初始化React Native项目时遇EEXIST权限错误求助

React Native初始化报错解决方法

问题描述

执行React Native初始化命令时出现权限与文件冲突错误:

Apples-iMac:React Native apple$ npx react-native@latest init AwesomeProject
Need to install the following packages:
react-native@0.72.5
Ok to proceed? (y) y
npm ERR! code EEXIST
npm ERR! syscall rename
npm ERR! path /Users/apple/.npm/_cacache/tmp/3ec76935
npm ERR! dest /Users/apple/.npm/_cacache/content-v2/sha512/9b/6d/3fb6c175ae11947aadbe72a2bd1a47fc51c94d8c5723e703f7391b987af885f65fe9e27cbb138e45616240491a95d46b973d5915027da8485d29e1c59859
npm ERR! errno EEXIST
npm ERR! Invalid response body while trying to fetch https://registry.npmjs.org/@babel%2fcompat-data: EACCES: permission denied, rename '/Users/apple/.npm/_cacache/tmp/3ec76935' -> '/Users/apple/.npm/_cacache/content-v2/sha512/9b/6d/3fb6c175ae11947aadbe72a2bd1a47fc51c94d8c5723e703f7391b987af885f65fe9e27cbb138e45616240491a95d46b973d5915027da8485d29e1c59859'
npm ERR! File exists: /Users/apple/.npm/_cacache/content-v2/sha512/9b/6d/3fb6c175ae11947aadbe72a2bd1a47fc51c94d8c5723e703f7391b987af885f65fe9e27cbb138e45616240491a95d46b973d5915027da8485d29e1c59859
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.

npm ERR! A complete log of this run can be found in: /Users/apple/.npm/_logs/2023-09-27T07_14_04_855Z-debug-0.log

错误原因

这是npm缓存目录的权限问题叠加文件冲突导致的:

  • 缓存目录下的目标文件已存在,npm无法正常将临时文件重命名到缓存路径
  • 当前用户对.npm缓存目录没有足够的读写权限

解决步骤

  • 强制清理npm缓存
    执行命令清除所有缓存文件,解决文件冲突:

    npm cache clean --force
    
  • 重新初始化项目
    缓存清理完成后,再次运行初始化命令:

    npx react-native@latest init AwesomeProject
    
  • 权限修复(如果上述步骤无效)
    手动修改.npm目录的所有权,确保当前用户拥有完整权限:

    sudo chown -R $USER:$GROUP ~/.npm
    

    执行后重新运行初始化命令即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 01:35:56