I got this problem when i expo publish my react native app with or without --release-channel dev
flag.I set up a config file environment.js to get different release version like this :
import Constants from "expo-constants";import { Platform } from "react-native";const localhost = Platform.OS === "ios" ? "localhost:8080" : "10.0.2.2:8080";const ENV = { localhost: { //apiUrl: localhost, apiUrl: "http:xxxx", }, dev: { apiUrl: "http:xxxx", }, staging: { apiUrl: "http:xxxx", // Add other keys you want here }, prod: { apiUrl: "http:xxxx", // Add other keys you want here },};const getEnvVars = (env = Constants.manifest.releaseChannel) => { // What is __DEV__ ? // This variable is set to true when react-native is running in Dev mode. // __DEV__ is true when run locally, but false when published. if (__DEV__ || env === undefined || env === null || env === "") { return ENV.localhost; } else if (env.indexOf("dev") !== -1) { return ENV.dev; } else if (env.indexOf("staging") !== -1) { return ENV.staging; } else if (env.indexOf("prod") !== -1) { return ENV.prod; }};export default getEnvVars;
I intercept the config with creation of new intance of axios like this :
import axios from "axios";import { getKey } from "./deviceStorage";import getEnvVars from "../../environment";const { apiUrl } = getEnvVars();const instance = axios.create({ // .. where we make our configurations baseURL: apiUrl,});instance.interceptors.request.use((config) => { const token = getKey("id_token"); token.then((value) => { config.headers.Authorization = value ? `Bearer ${value}` : ""; }); return config;});export default instance;
when i emulate on my device every thing work fine but when i expo publish and scan QR code with my device the app crash after splash screen and i got this error say :
Please any help thanks !!!