Expo Constants - Depreciated global?

Please provide the following:

  1. SDK: 40
  2. Platforms: Android, iOS
  3. Package: Constants

Hi,

I’ve just updated to SDK40 and i’m getting the following warning:

Your project is accessing the following APIs from a deprecated global rather than a module import: Constants (expo-constants).

The global “__expo” and “Expo” objects will be removed in SDK 41.

I’m only using Constants once. I’m installing it with expo install expo-constants and using it with the recommended import Constants from 'expo-constants'; but i’m still getting the warning.

Any assistance in resolving this would be great.

Thanks,

Hey @kemikalgeneral, there’s a good chance the issue is with one of your dependencies if you are confident it isn’t coming from your own code.

Cheers,
Adam

Hi @adamjnav,

I ran a global check for anything containing either __expo or Expo, but the only thing that is found is in node_modules > expo > build > depreciatedGlobal.js > logWarning() …which is your warning telling me about this warning!

The only instance of it in my whole project is the one i’ve mentioned above, and i’ve noticed it only happens on Android?!

Hi @adamjnav,

I was wondering if you have any news on this issue please?

I’m a little anxious as the docs say the globals __expo and Expo are being removed in the next update, and i’d rather not have my app break because of it.

Thanks

hi there!

try searching your node_modules for the string .Constants

Hi @notbrent,

Thanks for the suggestion, but nothing was found :frowning:

these are all of the possible globals: expo/Expo.fx.expo.tsx at b390dd652f75cec29d179165c6083ef51c090dd7 · expo/expo · GitHub

the only way you would see this log message is if the Constants property is accessed on one of these objects

Hi @notbrent,

I ran a project-wide search, and these are the files that contain anything with either
global.__expo | global.__exponent | global.Expo


global.__expo | global.__exponent

Expo.fx.expo.js
Expo.fx.expo.js.map


global.Expo

AnimatedDebug.js
AnimatedDebug.js.map
index.js


There are a bunch of files that contain .Constants, but only the ones listed above call it on global.

it doesn’t have to necessary be referred to as global.__expo.Constants (and others) - it could be __expo.Constants or window.__expo.Constants - all of these are considered “globals” in react-native

Hi @notbrent,

Thanks for the advice, but the results are the same :slightly_frowning_face:

i’m not sure i understand - there are several places in that screenshot that access Expo.Constants, such as react-native-safe-area-view. that’s exactly what you’re looking for. i’d recommend not using react-native-safe-area-view (now deprecated) and switching to react-native-safe-area-context instead

Hi @notbrent,

As previously mentioned, I’m not using these, which is why I’ve also included my package.json so you can see it’s not installed or part of my dependencies.

For instance, react-native-reanimated is in the dependencies, but again, I have not installed this. It was installed as part of another package.

Thanks,

Hi @kemikalgeneral

If I add the dependencies as per your package.json (which would have been a lot easier if you had pasted the file’s contents instead of just a screenshot) and run yarn then I see the following:

$ find node_modules -type f -print0 | xargs -0 grep -l 'Expo\.Constants'
node_modules/react-native-safe-area-view/index.js
node_modules/@expo/config-types/build/ExpoConfig.d.ts
node_modules/@expo/config-types/build/ExpoConfig.js.map
node_modules/react-native-reanimated/lib/commonjs/core/AnimatedDebug.js
node_modules/react-native-reanimated/lib/commonjs/core/AnimatedDebug.js.map
node_modules/react-native-reanimated/lib/module/core/AnimatedDebug.js
node_modules/react-native-reanimated/lib/module/core/AnimatedDebug.js.map
node_modules/react-native-reanimated/src/core/AnimatedDebug.js

So react-native-safe-area-view and react-native-reanimated are installed. The latter is not surprising, since it’s listed in your dependencies. Let’s look at them one at a time.

yarn why is useful for seeing why something is installed if you don’t have it listed in your dependencies. Unfortunately I don’t believe npm has a similar command:

$ yarn why react-native-safe-area-view
yarn why v1.22.10
[1/4] Why do we have the module "react-native-safe-area-view"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "react-native-safe-area-view@0.14.9"
info Reasons this module exists
   - "react-navigation#@react-navigation#native" depends on it
   - Hoisted from "react-navigation#@react-navigation#native#react-native-safe-area-view"
info Disk size without dependencies: "801KB"
info Disk size with unique dependencies: "1.07MB"
info Disk size with transitive dependencies: "1.35MB"
info Number of shared dependencies: 2
Done in 0.35s.

So that tells us that react-native-safe-area-view is installed because it’s a dependency of react-navigation. (Or at least the version of react-navigation that you have installed.)

OK, so you have react-navigation version 3 in your dependencies. The documentation for react-navigation version 3 says:

Next, install react-native-gesture-handler and react-native-reanimated

so that explains why you have react-native-reanimated installed.

It turns out that upgrading to React Navigation 5.x gets rid of the react-native-safe-area-view dependency. Unfortunately version 5 still wants you to install react-native-reanimated and when you do that you get version 1.13.2 which has references to Expo.Constants.

Even if you install react-native-reanimated@^2.0.0 there is still a reference to Expo.Constants, although only in:

node_modules/react-native-reanimated/src/core/AnimatedDebug.js

whereas with react-native-reanimated@1.13.2 there were also references here:

node_modules/react-native-reanimated/lib/commonjs/core/AnimatedDebug.js
node_modules/react-native-reanimated/lib/module/core/AnimatedDebug.js

@notbrent since React Navigation tells you to install react-native-reanimated which contains references to Expo.Constants, what is the recommended way to get rid of these warnings when using React Navigation?

1 Like

Hi @wodin,

Thanks very much for the help with this, it explains a lot :smile:

The only problem is, how do I fix the issue of these dependencies (that I don’t use) referencing something that is going to be removed in the next update, which is more than likely going to break my app?

Thanks again,

@kemikalgeneral I have just done some more poking around.

Unless I am mistaken, react-native-reanimated is only referred to by @react-navigation/drawer.
I created a new Expo project, installed React Navigation version 5 as per the Getting Started guide, then installed @react-navigation/drawer. Again I found references to Expo.Constants in react-native-navigation.

Then I replaced the contents of App.js with the example from here.

When I ran expo start and opened/closed the drawer etc. I did not get any warnings about Expo.Constants.

So I suggest you upgrade to React Navigation 4. I think you will probably still get warnings. If so, upgrade to React Navigation 5. I think that should get rid of the warnings.

1 Like

in expo sdk 41 we are bumping the reanimated v2 where this global usage has already been removed: [v1] Replace global.Expo.Constants with NativeModules check by brentvatne · Pull Request #1803 · software-mansion/react-native-reanimated · GitHub

1 Like

Thanks, @notbrent

I see that was merged after the 2.0.0 release, so I currently still get the following:

$ expo init test
✔ Choose a template: › blank                 a minimal app as clean as an empty canvas
[...]
$ cd test
$ yarn add react-native-reanimated@^2.0.0
[...]
info Direct dependencies
└─ react-native-reanimated@2.0.0
[...]
$ find node_modules/react-native-reanimated -type f -print0 | xargs -0 grep -l 'Expo\.Constants'
node_modules/react-native-reanimated/src/core/AnimatedDebug.js

Is the plan to have Expo SDK 41 depend on react-native-reanimated version 2.0.1?

Will React Navigation version 3 still work in Expo SDK version 41 with react-native-reanimated version 2.x?

1 Like

Thanks very much @wodin, I’ll jump on this and I really appreciate your help.

All the best,

1 Like

we will use a version that will be released later this week or next with a couple other changes

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.