这是我在 Sample-Expo-Project 中的代码。我无法使用 process.env 以及 EAS Secrets 中添加环境变量。我已在 EAS 中添加了机密,但在构建时无法读取。在这两种情况下我都变得不确定。请指出我做错的地方,我已经尝试了很多天了。
应用程序.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",
},
});
Run Code Online (Sandbox Code Playgroud)
巴别塔配置
module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo"],
plugins: …
Run Code Online (Sandbox Code Playgroud)