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.
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?!
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.
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
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
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.
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:
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.)
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:
@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?
Thanks very much for the help with this, it explains a lot
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?
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.
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?