Custom Dev Client - Extra variables are undefined

Hello,
I have a Custom Development Client built using EAS Build and an extra key in my app.config.js like this:

extra: {
        apiUrl: process.env.API_URL ?? 'http://localhost:3000/api'
    }

I use expo-constants as described here: Environment variables in Expo - Expo Documentation.
I expected Constants.manifest2.extra.apiUrl to be http://localhost:3000/api, however, I cannot find any trace of apiUrl in all of the manifest2 object.
I did read all the documentation but did not find anything related.
Did I miss something?

I’m using the latest SDK.

Thanks!

Hey @thomasgrivet,
Could you provide your manifest (or the url where it lives which should look something like https://u.expo.dev/fe6b6a94-d840-4768-b609-8d2ccbd43f78?runtime-version=exposdk:44.0.0&platform=ios&channel-name=main)

Sure! Can you just tell me where it is located? I cannot seems to find it after building my development client on EAS servers.

Expos choice of having variables on Constants.manifest2 in some cases, Constants.manifest in some cases and also introduce Updates.manifest that works in some cases without clear documentation is sub-optimal to say the least and cause a lot of headaches and cursing :slight_smile: It also breaks libraries like bugsnag as they expect Constants.manifest to exist, but does not in some cases when using EAS channels.

It should be a pretty darn straightforward job to provide a unified API or interface/library for getting these values if it only was properly documented, why it is not already unified from expos side is unclear to me.

What is the suggested bulletproof way of getting the SDK version and the “extra” section from the manifest?

Ah, I thought your issue was when using a project you had published with EAS update, but it sounds like you’re just trying to access them locally?
Either way, there is documentation here Using environment variables with EAS Update - Expo Documentation on accessing env variables. It appears they live under Constants.manifest2?.extra?.expoClient?.extra

So to get the environment variables in a bullet proof way:

const extra = 
Constants.manifest2?.extra?.expoClient?.extra || Constants.manifest?.extra

And what about Expo SDK version and other things that exist on manifest directly?

This API breaks bugsnag seemingly for no good reason, IMO Expo should provide some stable API for getting these kinds of values that does not depend on the runtime context - https://github.com/bugsnag/bugsnag-js/issues/1683

Thanks for your reply, I don’t want to publish any update for now. I have a .app created using EAS Build which is a development build. I use expo start --dev-client to start the metro bundler (which is why I expect the variable to be http://localhost:3000/api).
I did read the entire documentation but I did not find anything related to my problem.
I tried accessing Constants.manifest2?.extra?.expoClient?.extra but it is undefined.

I also have another problem which only occurs when adding the extra key in app.config.js and trying to select my development server in the servers list, I get the following error:

Screenshot 2022-02-04 at 07.00.37

I do not have this problem after removing the extra key, selecting my development server and re-adding the extra key and hot reloading.

Thanks

EDIT: Found the problem, my extra object did not contain any eas object. This was only described in the Using environment variables with EAS Update documentation but nowhere else.
Like @kennethlynne said, I would prefer having one nice interface where I could store and manage my environment variables using EAS services. It’s kind of a pain to know exactly what to do at each stage of delivery with the current way of handling them, but I guess that’s mostly due to the transition being made to everything EAS.
Anyway, thank you so much for the replies, have a nice day!

Regarding the projectId issue we also started seeing that, and from debugging and reading source code we managed to figure out a workaround: Add this under the extra field

eas: { projectId: '<found in expo.dev under project overview>' }, // undocumented property that expo-cli seems to require to determine how to set up expo-updates https://github.com/expo/expo-cli/pull/3890/files#diff-663d514e69e821be5315a630820a5f710de0fba6d686012702292d3aecf0cf23
1 Like