app.json holds plain values. It can't contain variables or anything computed. When one value should feed several keys, or the config needs any logic, you write it in TypeScript as app.config.ts. Expo runs that file and uses whatever it returns, so how the function treats the values from app.json, and which file Expo picks when several exist, decide what your app ends up with.
Key terms
- static config: the JSON form of the app config,
app.config.jsonorapp.json. - dynamic config: the code form of the app config,
app.config.jsorapp.config.ts, which Expo evaluates. - ConfigContext: the type of the argument Expo passes to a config function, exported from
expo/config. - ExpoConfig: the type of a complete app config, also exported from
expo/config.
A function between app.json and Expo CLI
A dynamic config can export an object, but exporting a function is the better fit when the project also has an app.json. Expo CLI reads app.json first and hands the normalized result to your function. Whatever the function returns becomes the config.
The function receives a ConfigContext with four fields: projectRoot, staticConfigPath, packageJsonPath and config. The one you use is config, typed Partial<ExpoConfig>. It is not the raw file: Expo fills in the defaults first, so config.name holds a name even when app.json leaves it out.
Because the file is code, it can hold variables and ESM import statements, and in TypeScript you get optional chaining and nullish coalescing. app.config.ts needs no extra setup. It can't import other TypeScript files or follow tsconfig.json customizations without the tsx package.
The Trailmix config in TypeScript
The app.config.ts example below keeps Trailmix's app.json and adds one variable, appId, used for both the iOS bundle identifier and the Android package. Watch the order of the keys in the returned object.
The first line inside the object is ...config, which copies every value from app.json (icon, scheme, orientation and the rest). The keys after it override what they name. The nested ...config.ios and ...config.android do the same one level down, so other settings under ios and android in app.json survive while bundleIdentifier and package are replaced.
The return type is ExpoConfig, which requires name and slug as strings. Since config is a Partial<ExpoConfig>, the example sets both explicitly to satisfy the type.
Leave out the spread and app.json disappears
When an app.config file exists, Expo builds the final config from what the function returns, plus the defaults. Anything from app.json that the function doesn't return is gone. A config written as
tsexport default ({ config }: ConfigContext): ExpoConfig => ({ name: 'Trailmix', slug: 'trailmix', });
loses the icon, the scheme and the store identifiers, even though app.json still lists them. Starting the object with ...config is the usual way to layer a dynamic config on top of the static one.
How Expo picks the config
Expo resolves the config in six steps:
- It reads the static config from
app.config.json, falling back toapp.json. - It reads the dynamic config if an
app.configfile exists. It tries the extensions.ts,.mts,.cts,.mjs,.cjsand.jsin that order, so with bothapp.config.tsandapp.config.jspresent, the TypeScript file wins and the other is ignored. - If the dynamic config exports a function, Expo calls it with the static config as
{ config }. - The return value is the final config, and it can't be a Promise. An
asyncfunction fails withConfig file ... cannot return a Promise., reported underError reading Expo config atfollowed by the file path. - Any function left in the config is called and replaced by its return value, except under the top-level
pluginsandmodskeys, which are kept as they are. - If the final config has a top-level
expoobject, Expo uses that object in place of the root and ignores every other top-level key.
CLI tools can update a static config for you, but they never edit app.config.ts. When a tool can't apply its change through the static config, for example because your function doesn't spread ...config into what it returns, it reports Cannot automatically write to dynamic config at: app.config.ts and leaves the change to you.
The dev server reads the config again each time it builds a manifest, so after editing app.config.ts, reload the app and run npx expo config to confirm the result.
Code Examples
import { ConfigContext, ExpoConfig } from 'expo/config';
// Used for both the iOS bundle identifier and the Android package
const appId = 'com.example.trailmix';
export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
name: 'Trailmix',
slug: 'trailmix',
ios: {
...config.ios,
bundleIdentifier: appId,
},
android: {
...config.android,
package: appId,
},
});