【问题标题】:Expo/React Native: Can't find image file after ejecting to bare workflowExpo / React Native:弹出到裸工作流后找不到图像文件
【发布时间】:2021-12-26 07:05:55
【问题描述】:

我有一个 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 构建时正确捆绑图像的一种方式?

【问题讨论】:

    标签: react-native expo


    【解决方案1】:

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

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-05
      • 2020-03-08
      • 2021-08-05
      • 1970-01-01
      • 2020-05-24
      • 2022-11-20
      • 1970-01-01
      • 2022-08-23
      相关资源
      最近更新 更多