Unhandled promise rejection: undefined is not an object (evaluating _expoLocation.requestForegroundPermissionsAsync)

Viewed 1108

I'm trying to get the user location in React Native with Expo (Managed Workflow for Android) following the official example for expo-location. Here is my function:

import Location from 'expo-location';

const handleLocationFinder = async () => {
  const { status } = await Location.requestForegroundPermissionsAsync();
  if (status !== 'granted') {
    console.log('Permission denied. Enter the location manually.');
    return;
  }
  const location = await Location.getCurrentPositionAsync({});
  console.log(location);
};

However, when I call this function, I get this warning:

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_expoLocation.default.requestForegroundPermissionsAsync')]

What I tried:

  • Reinstall the app in the emulator;
  • Fresh emulator;
  • My actual phone (Android 8.0);
  • Add "permissions": ["ACCESS_FINE_LOCATION"] to app.json (although expo seems to do this);
  • expo upgrade;
  • Pray.

Platform info (after expo upgrade):

  • Android 11.0 (Pixel 4 emulated)
  • expo: 41.0.1
  • react-native: sdk-41.0.0
  • expo-location: 12.0.4
1 Answers

I got the same issue and when i changed:

import Location from "expo-location";

To:

import * as Location from "expo-location";

Like what in the documentation, it worked for me.

Related