6

I would like to debug on my mobile/simulator and point it dynamically to API.

const {manifest} = Expo.Constants; 
const api = manifest.packagerOpts.dev
? manifest.debuggerHost.split(':').shift().concat(':3000')
: 'productionurl.com'


export function getEvents(){
    return fetch('http://${api}/events')
    .then(response => response.json())
    .then(events => events.map(e =>({ ...e, date: new Date(e.date)})));
}

I am getting the following error:

undefined is not an object(evaluating'_expo.default.Constants')

chandra
  • 83
  • 1
  • 2
  • 8

3 Answers3

15

I work with "sdkVersion": "35.0.0". It seems that Expo changed its API. They extracted and moved some parts into separate packages. Now for this case you need to install a separate dependency:

npm i --save expo-constants

And then to import FileSystem object independently for your component:

import Constants from 'expo-constants';
Roman
  • 19,236
  • 15
  • 93
  • 97
6

Bring the complete module of the expo with:

import * as Expo from 'expo'
fullStackChris
  • 1,300
  • 1
  • 12
  • 24
hong developer
  • 13,291
  • 4
  • 38
  • 68
0

When you are working in Snack.expo.io, if you get this error, use the code:

import Constants from 'expo-constants';

This worked for me.

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Raj
  • 51
  • 1
  • 5