I’m working on an Expo project (SDK 51) that has been ejected to a bare workflow to handle builds myself without using EAS services. I'm using react-native-code-push
and code-push-standalone
to push over-the-air updates. My assets (images and fonts) work fine in the initial build, but after a CodePush update, all the assets are missing.
expo-image
, expo-asset
code-push-standalone
npx expo export
In the initial build, the images and fonts are bundled and displayed correctly. For example, an image path in the initial build looks like this:
file:///private/var/containers/Bundle/Application/[id]/MyApp.app/assets/src/assets/images/login/login-header-background.png
After applying a CodePush update, all images and fonts disappear. The path of the assets after CodePush looks like this:
file:///var/mobile/Containers/Data/Application/[id]/Library/Application%20Support/CodePush/[codepush-id]/assets/src/assets/images/login/login-header-background.png
Image loading example using expo-image
and require
:
import { Image } from 'expo-image';
<Image
style={{ height: 360 }}
source={require('../../assets/images/login/login-header-background.png')}
/>
I also tried loading the image using expo-asset
:
import { Asset } from 'expo-asset';
import { Image } from 'expo-image';
const image = Asset.fromModule(require('@/assets/images/login/login.png')).uri;
<Image style={{ height: 250 }} source={{ uri: image }} />
Here is part of my app.json
configuration:
{
"expo": {
"assetBundlePatterns": ["./src/assets/**/*"],
"plugins": [
["expo-font", { "fonts": ["./src/assets/fonts/*.ttf"] }],
["expo-asset", { "assets": ["./src/assets/images/*.png"] }]
]
}
}
I export my app using:
npx expo export
Then I push the update using:
code-push-standalone release MyApp-iOS ./dist/_expo/static/js/ios/index-123.hbc "1.0.34" --deploymentName Staging --mandatory --description "Hotfix: Updated login button text"
require()
to load static assets (images and fonts).Asset.fromModule()
../dist/assets
folder after the Expo export.After applying a CodePush update, none of the assets (images or fonts) load anymore. They seem to be missing or inaccessible. I suspect this is due to how CodePush handles assets in a different directory, but I'm unsure how to ensure that my app correctly resolves assets from the new location.
How can I make sure my images and fonts load correctly after a CodePush update?
To fix the missing assets issue after a CodePush update, follow these steps:
Change how you define images by explicitly listing them:
{
"expo": {
"plugins": [
["expo-asset", { "assets": ["./src/assets/images/not-found.png"] }]
]
}
}
Load images without require(), relative paths, or file extensions:
import { Image } from 'expo-image';
<Image source="not-found" />
Rebuild your app (npx expo run:ios) and test to ensure assets load properly