Expo/React 本机:弹出到裸工作流程后找不到图像文件

Expo/React Native: Can't find image file after ejecting to bare workflow

我有一个 Expo 项目,其中 <Image /> 组件来自进口:

import logoImage from './assets/logo-medium.png';

...

<Image source={logoImage} />

使用 expo run:ios -d 构建时,这在我的设备上运行良好。但是,当我使用 XCode 构建项目时,图像不存在,并且我看到此错误:

[native] Could not find image file:///Users/username/Library/Developer/CoreSimulator/Devices/B76D59AF-9599-4174-991B-AE484575B79C/data/Containers/Data/Application/A57C6E10-3DF9-46E0-8B56-7760AF5199C6/Library/Application%20Support/.expo-internal/assets/assets/logo-medium.png

当我尝试手动查找该文件时,没有 ...Application Support/.expo-internal 目录。

有没有其他方法可以指定图像位置?或者从 XCode 构建图像时正确捆绑图像的方法?

我遇到了同样的问题,请确保两件事:

  1. 在网络上找到的潜在解决方案之一 - https://forums.expo.dev/t/assets-missing-only-in-ios-release-build-after-ejecting/42759
Ok I found out the problem.
When ejecting, expo is supposed to generate a metro.config.js file that looks like that:

module.exports = {
  transformer: {
      assetPlugins: ['expo-asset/tools/hashAssetFiles']
  }
};
  1. 您的 metro.config.js 文件应该有 .js 扩展名而不是 .ts