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

Arch Linux执行npx react-native init时遭遇ENOTEMPTY错误求助

解决Arch Linux下npx react-native init的ENOTEMPTY错误

错误日志(中文翻译)

[hassan@arch ~]$ npx react-native init Test
需要安装以下包:
  react-native@0.69.4
是否继续?(y) y
npm ERR! 代码 ENOTEMPTY
npm ERR! 系统调用 rename
npm ERR! 路径 /home/hassan/.npm/_npx/7930a8670f922cdb/node_modules/metro-source-map
npm ERR! 目标路径 /home/hassan/.npm/_npx/7930a8670f922cdb/node_modules/.metro-source-map-rnpcIOap
npm ERR! 错误码 -39
npm ERR! ENOTEMPTY: 目录非空,重命名 '/home/hassan/.npm/_npx/7930a8670f922cdb/node_modules/metro-source-map' -> '/home/hassan/.npm/_npx/7930a8670f922cdb/node_modules/.metro-source-map-rnpcIOap'

npm ERR! 本次运行的完整日志可在以下位置查看:
npm ERR!     /home/hassan/.npm/_logs/2022-08-19T10_50_05_222Z-debug-0.log

错误原因

这是npm处理npx临时依赖时的缓存冲突问题,npx临时目录中的metro-source-map未被正确清理,导致重命名操作失败。

修复步骤

  • 清理报错的npx临时目录
    直接删除指定的npx缓存目录:

    rm -rf /home/hassan/.npm/_npx/7930a8670f922cdb
    

    若不确定所有npx临时目录,可清空整个npx缓存:

    rm -rf ~/.npm/_npx
    
  • 清理npm全局缓存(可选)
    若清理npx缓存后问题仍存在,执行npm缓存强制清理:

    npm cache clean --force
    
  • 重新初始化项目
    再次运行初始化命令:

    npx react-native init Test
    
  • 备选方案:跳过缓存指定版本
    若上述步骤无效,尝试跳过缓存并指定react-native版本:

    npx --no-cache react-native@0.69.4 init Test
    

内容的提问来源于stack exchange,提问作者Hassan El dika

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 05:49:12