Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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')

like image 893
chandra Avatar asked Dec 01 '22 13:12

chandra


2 Answers

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';
like image 128
Roman Avatar answered Dec 04 '22 13:12

Roman


Bring the complete module of the expo with:

import * as Expo from 'expo'
like image 37
hong developer Avatar answered Dec 04 '22 14:12

hong developer