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

迁移React Native至Expo遇expo.modules.interfaces.filesystem.AppDirectories缺失错误

问题解决:找不到expo.modules.interfaces.filesystem.AppDirectories导致图标无法加载

可能的原因及修复步骤

1. 统一Expo依赖版本

这个错误大多源于Expo核心包版本不兼容,尤其是expo-asset和expo-file-system这类关联模块。执行以下命令自动修复版本冲突:

npx expo install --fix

2. 清理缓存并重建项目

缓存残留可能导致模块引用异常,按顺序执行以下操作:

  • 清理Metro缓存:
    npx expo start --clear
    
  • 针对iOS项目:删除ios/Pods文件夹,再执行pod install
  • 针对Android项目:删除android/.gradle和android/app/build文件夹,再执行./gradlew clean

3. 检查图标配置路径

确认app.json/app.config.js中的icon字段指向正确的资源路径,示例:

{
  "expo": {
    "icon": "./assets/icon.png"
  }
}

确保资源文件存在且路径无拼写错误。

4. 移除React Native CLI链接残留

如果项目之前用React Native CLI手动链接过模块,迁移到Expo后需清理残留:

  • 删除项目根目录下的react-native.config.js(若存在)
  • 所有Expo相关依赖都通过expo install安装,避免使用npm install/yarn add触发手动链接冲突。

5. 规范Asset调用逻辑

若项目自定义了Asset下载逻辑,需改用Expo官方API,示例:

import { Asset } from 'expo-asset';

const loadAppIcon = async () => {
  const iconAsset = Asset.fromModule(require('./assets/icon.png'));
  await iconAsset.downloadAsync();
};

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 12:09:50