小编Har*_*rma的帖子

如何在 expo 项目中读取 EAS 构建秘密和环境变量。变得未定义?

这是我在 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)

security react-native expo

8
推荐指数
1
解决办法
2353
查看次数

标签 统计

expo ×1

react-native ×1

security ×1