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

使用npx expo run:ios时遭遇HTTP 403错误,无法创建原生目录

Expo run:ios 触发 HTTP 403 Forbidden 错误(无法创建原生目录)

使用Expo + React Native开发移动应用,遵循官方本地开发构建流程(未使用EAS),npx expo start可正常启动,Web端能通过http://localhost:8081访问,但执行npx expo run:ios或npx expo prebuild时触发以下错误:

HTTP 403 Forbidden
✖ Failed to create the native directory
You may want to delete the ./ios and/or ./android directories before trying again.

已尝试操作:

  • 安装Xcode及所有必要Expo依赖包
  • 本地已登录Expo账号
  • 删除./ios/./android目录后重试
  • 通过USB连接iOS设备并添加--device参数运行,问题依然存在

项目基于Expo模板代码,完整app.json配置如下:

{  
  "expo": {    
    "name": "<app_name>",    
    "slug": "<app_name>",    
    "version": "1.0.0",    
    "platforms": ["ios", "android", "web"],    
    "orientation": "portrait",    
    "icon": "./assets/images/icon.png",    
    "scheme": "myapp",    
    "userInterfaceStyle": "automatic",    
    "newArchEnabled": true,    
    "ios": {      
      "supportsTablet": true,      
      "bundleIdentifier": "com.<app_name>"    
    },    
    "android": {      
      "adaptiveIcon": {        
        "foregroundImage": "./assets/images/adaptive-icon.png",        
        "backgroundColor": "#ffffff"      
      }    
    },    
    "web": {      
      "bundler": "metro",      
      "output": "static",      
      "favicon": "./assets/images/favicon.png"    
    },    
    "plugins": [      
      "expo-router",      
      [        
        "expo-splash-screen",        
        {          
          "image": "./assets/images/splash-icon.png",          
          "imageWidth": 200,          
          "resizeMode": "contain",          
          "backgroundColor": "#ffffff"        
        }      
      ]    
    ],    
    "experiments": {      
      "typedRoutes": true    
    }  
  }
}

解决方案尝试

1. 更新Expo CLI至最新稳定版

403错误常与版本兼容性有关,直接调用最新版CLI执行构建:

npx expo@latest run:ios

或全局更新CLI:

npm install -g expo-cli

2. 重新登录Expo账号

重置登录会话,确保账号权限有效:

npx expo logout
npx expo login

若项目关联团队,确认账号拥有团队项目的操作权限。

3. 临时禁用新架构

当前启用了newArchEnabled: true,新架构在本地构建阶段可能存在兼容问题,修改app.json后重试:

"newArchEnabled": false

删除./ios/./android目录,重新执行npx expo run:ios。

4. 检查网络代理与防火墙

HTTP 403可能是本地代理或防火墙拦截了Expo的请求:

  • 关闭VPN、Charles等代理工具
  • 切换至手机热点网络尝试构建
  • 确保本地网络允许访问Expo的服务域名

5. 清理项目缓存与依赖

彻底清理缓存后重新安装依赖:

npx expo start --clear
rm -rf node_modules package-lock.json
npm install
npx expo run:ios

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 18:34:51