This is my code in a Sample-Expo-Project. I am not able to add environment variable using process.env and also in EAS Secrets. I have added secrets in EAS but cannot read while building. In both cases I am getting undefined. Please spot where I am doing wrong, I am trying from multiple days.
App.js
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
export default function App() {
console.log(process.env); // Getting {"NODE_ENV": "development"}
console.log(process.env.HELLO); // Getting undefined
return (
<View style={styles.container}>
<Text>From Env {process.env?.HELLO}</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
Babel Config
module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo"],
plugins: ["transform-inline-environment-variables"],
};
};
Env File
HELLO=HelloEveryone
Package.json
{
"name": "sample-expo-app",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"expo": "~48.0.15",
"expo-status-bar": "~1.4.4",
"react": "18.2.0",
"react-native": "0.71.7"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"babel-plugin-transform-inline-environment-variables": "^0.4.4"
},
"private": true
}