Coding Elements
Coding Elements

Reputation: 1038

Expo error: Cannot read property 'statusBarHeight' of null

How to fix this error in Expo v34.0.0?

Expo error Cannot read property statusBarHeight of null

Upvotes: 2

Views: 2942

Answers (2)

Coding Elements
Coding Elements

Reputation: 1038

In Expo, you can no longer import directly from 'expo', so change from (the old way):

import { Constants } from 'expo'; // OLD WAY

to (the updated way):

import Constants from 'expo-constants'; // NEW WAY

Similarly, if you are using the following features, use this format:

import MapView from 'react-native-maps';

import * as Location from 'expo-location';

import * as Permissions from 'expo-permissions';

import { DeviceMotion } from 'expo-sensors';

Expo documentation is quite helpful.

If you are using the online Expo editor, you will be prompted to install the packages, so just click OK. Otherwise, run:

expo install expo-constants

Upvotes: 2

Abdeen
Abdeen

Reputation: 932

Expo separated a lot of their previously joined libraries and Constants is one of them, to get the constants now, follow along:

  1. Install expo-constants by running this on your project directory:
expo install expo-constants
  1. import Constants where needed as follows
import Constants from 'expo-constants';
  1. Retrieve statusBarHeight like this:
const barHeight = Constants.statusBarHeight;

More on the new documentations for Expo SDK 34 can be found here.

Hope this Helps!

Upvotes: 1

Related Questions