expo: Constants.manifest.extra is always undefined (Windows)(Typescript)
Constants.manifest.extra is undefined repo here
Description
when trying to display the value of extra constants this gives undefined.
Expected Behavior
import Constants from 'expo-constants';
console.log("extra - ", Constants.manifest.extra);
// extra - { "mode": "DEVELOPMENT" }
Observed Behavior
I have observed that setting the value directly in app.json continues as undefined.
import Constants from 'expo-constants';
console.log("extra - ", Constants.manifest.extra);
// extra - undefined
Environment
Expo CLI 3.17.24 environment info:
System:
OS: Windows 10 10.0.18362
Binaries:
Node: 12.14.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.19.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
npmPackages:
expo: 37.0.8 => 37.0.8
react: 16.13.1 => 16.13.1
react-native: https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz => 0.61.4
phone
phone: simulator, emulator and Huawei
platform: android
model: LDN-LX3
Reproducible Demo
app.config.js
import { ExpoConfig, ConfigContext } from '@expo/config';
import manifiest from './package.json';
const Mode = {
DEVELOPMENT: 'DEVELOPMENT',
QA: 'QA',
PRODUCTION: 'PRODUCTION',
}
export default ({ config }: ConfigContext): ExpoConfig => ({
...config,
version: manifiest.version,
// All values in extra will be passed to your app.
extra: {
mode: Mode.DEVELOPMENT,
},
});
app.json
{
"expo": {
"name": "myapp",
"slug": "myapp",
"scheme": "my-app-schema",
"privacy": "unlisted",
"version": "1.0.1",
"orientation": "portrait",
"description": "My app description",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "cover"
},
"platforms": [
"ios",
"android",
"web"
],
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"android": {
"package": "co.com.example.myapp",
"versionCode": 1
},
"androidStatusBar": {
"hidden": false,
"translucent": true,
"barStyle": "light-content",
"backgroundColor": "#00000000"
},
"ios": {
"supportsTablet": true,
"bundleIdentifier": "co.com.example.myapp",
"buildNumber": "1.0.0"
}
}
}
src/setup.constants.ts
import Constants from 'expo-constants';
console.log("extra", Constants.manifest.extra);
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 20 (5 by maintainers)
Just to update, actually it started working for both iOS and Android for me but only if the config is present on
app.jsonas an empty key.I was also experiencing this issue, but it appears to be a caching problem. I had a misconfigured variable being loaded into manifest.extra, and after correcting it I was still unable to see it despite trying several restarts of both the Expo client and server. The only thing that eventually worked is force clearing the data on the Expo client. After doing this, the updated environment variable is now being picked up and can be accessed from my application.
I also tried to repro the issue using @juandav’s repo, and it worked fine straight away. However if I manually changed the value in app.config.ts, the app would continue to load the old value.
Facing same issue for Expo CLI version 3.22.3 Windows 10 OS It works fine on Mac
Hi @juandav, thanks for the repository (those things are useful 😄). But also here I’m getting the following output:
Could you try upgrading your
expo-cliand/or project withexpo upgrade?Hi @juandav! Thanks for the issue report. Unfortunately, I can’t reproduce this behavior. For me, your provided code works fine. I did have to edit the
schemein yourapp.jsonto"scheme": "my-app-schema". The reason for this are the upper case letters, those are invalid. Could you try editing this on your end as well and restart the project withexpo start --clear? 😄If you are using the bare workflow instead, the manifest isn’t available. That might cause this issue for you too, but only if you are running bare instead of managed.
Hope it helps!