小编cha*_*dra的帖子

undefined不是对象(评估'_expo.default.Constants')

我想在移动设备/模拟器上进行调试并将其动态指向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)})));
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

未定义不是对象(正在评估'_expo.default.Constants')

react-native manifest.json expo

2
推荐指数
2
解决办法
2832
查看次数

未定义不是对象(评估'_expo.default.Constants')

我在Constantsin处遇到错误const{manifest}=Expo.Constants并向我显示错误,因为 undefined 不是对象。我无法得到它。任何人都可以帮助我消除该错误。

我正在尝试在我的计算机上运行的 API 和我在手机上调试时建立连接。无论 IP 地址是什么,它都应该连接。

import moment from 'moment';
import Expo from 'expo';

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

const url ='http://localhost:3000';

export function getEvents(){
    return fetch(url)
    .then(response => response.json())
    .then(events => events.map( e =>({...e})));
}
export function formatDateTime(dateString){
    const parsed = moment(new Date(dateString));

    if(!parsed.isValid()){
        return dateString;
    }

    return parsed.format('H A on DD MMM YYYY');
}
export function formatDate(dateString){
    const parsed = moment(new Date(dateString));

    if(!parsed.isValid()){
        return dateString; …
Run Code Online (Sandbox Code Playgroud)

module momentjs react-native expo

2
推荐指数
1
解决办法
3500
查看次数

标签 统计

expo ×2

react-native ×2

manifest.json ×1

module ×1

momentjs ×1