goatandsheep / react-native-dotenv

Load react native environment variables using import statements for multiple env files.
https://www.npmjs.com/package/react-native-dotenv
MIT License
793 stars 47 forks source link

Building Expo App locally Fails: envs are not defined in local build process. #487

Open AyoCodess opened 6 months ago

AyoCodess commented 6 months ago

Describe the bug envs are not defined in local build process.

To Reproduce Steps to reproduce the behavior: local builds

Expected behavior env should be loaded into build process

Screenshots Screenshot 2024-02-17 at 09 41 38 edit: (IM USING EXPOPUBLIC)

Desktop (please complete the following information): Mac book pro

Additional context My app picks up the envs while developing just fine. it only failed when i build the app.

am i missing something in my set up?

module.exports = function (api) {
  api.cache(false)

  return {
    presets: [
      ['babel-preset-expo',{ jsxImportSource: 'nativewind' }],
      'nativewind/babel'
    ],
    plugins: [
      ['react-native-reanimated/plugin'],
      [
        'module:react-native-dotenv',
        {
          envName: 'APP_ENV',
          moduleName: "@env",
          path: ".env",
          allowUndefined: false,
          safe: true,
          verbose: false
        }
      ]
    ]
  };
};
declare module '@env' {
  export const EXPO_PUBLIC_CONVEX_URL: string;
  export const EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY: string;
  export const EXPO_PUBLIC_SECRET: string;
  export const EXPO_PUBLIC_SERVER_URL: string;
  export const EXPO_PUBLIC_E_LIST: string;
}

works as expected during development.

import { EXPO_PUBLIC_CONVEX_URL, EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY } from "@env";

github-actions[bot] commented 6 months ago

Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/487

goatandsheep commented 6 months ago

Reinstall as devDependency

AyoCodess commented 6 months ago

Reinstall as devDependency

Thanks for getting back to me. This is my package.json. I get the same error. Screenshot 2024-02-17 at 21 02 04

when i run eas build --local for ios. in the eas cli, it says no env are loaded, as it needs to read these from the eas.json. but i do not want to put api keys obviously in there as plain-text. Screenshot 2024-02-17 at 23 46 12

i have the same error when running the build uisng eas services Screenshot 2024-02-17 at 23 48 04

{
  "name": "mobile",
  "version": "1.0.1",
  "main": "index.js",
  "scripts": {
    "start": "expo start",
    "droid": "expo start --android -c ",
    "ios": "expo start --ios -c",
    "web": "expo start --web",
  },
  "dependencies": {
    "@clerk/clerk-expo": "^0.19.27",
    "@expo/config": "~8.5.0",
    "@hookform/resolvers": "^3.3.3",
    "@react-native-async-storage/async-storage": "^1.21.0",
    "@repo/api": "*",
    "@repo/auth": "*",
    "dayjs": "^1.11.10",
    "expo": "^50.0.4",
    "expo-constants": "~15.4.5",
    "expo-crypto": "~12.8.0",
    "expo-dev-client": "~3.3.7",
    "expo-linking": "~6.2.2",
    "expo-router": "~3.4.7",
    "expo-secure-store": "~12.8.1",
    "expo-status-bar": "~1.11.1",
    "expo-updates": "~0.24.9",
    "expo-web-browser": "~12.8.2",
    "nativewind": "^4.0.16",
    "react": "18.2.0",
    "react-hook-form": "^7.49.2",
    "react-native": "0.73.2",
    "react-native-calendars": "^1.1303.0",
    "react-native-dropdown-select-list": "^2.0.5",
    "react-native-gesture-handler": "~2.14.0",
    "react-native-get-random-values": "^1.10.0",
    "react-native-gifted-charts": "^1.4.7",
    "react-native-pager-view": "^6.2.3",
    "react-native-progress": "^5.0.1",
    "react-native-reanimated": "~3.6.2",
    "react-native-safe-area-context": "4.8.2",
    "react-native-screens": "~3.29.0",
    "react-native-toast-message": "^2.2.0",
    "superjson": "2.2.1",
    "zod": "^3.22.4",
    "zustand": "^4.5.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@expo/config-plugins": "~7.8.0",
    "@repo/eslint-config": "*",
    "@repo/prettier-config": "*",
    "@repo/tailwind-config": "*",
    "@repo/typescript-config": "*",
    "@types/node": "^20.11.19",
    "@types/react": "~18.2.14",
    "react-native-dotenv": "^3.4.9",
    "@types/react-native-dotenv": "^0.2.2",
    "@types/react-native-get-random-values": "^1.8.2",
    "tailwind": "^4.0.0",
    "typescript": "^5.1.3"
  },
  "private": true,
  "eslintConfig": {
    "root": true,
    "extends": [
      "@repo/eslint-config/react"
    ],
    "ignorePatterns": [
      "expo-plugins/**"
    ]
  }
}
AyoCodess commented 6 months ago

added new images.

Is this relevant: https://docs.expo.dev/guides/environment-variables/#how-to-read-from-environment-variables

goatandsheep commented 6 months ago

@AyoCodess unfortunately no it's not particularly relevant. It's a separate way of loading environment variables that works quite well. You may be able to use that method instead of this library altogether. I haven't tried it out myself though so if you do, please let me know! Thank you for confirming it's a devDependency. I'll check it off in your issue description. Do you have a env.d.ts file? If you have an example repo of this not working it helps me tremendously as I can pinpoint exactly where the issue may be :)

AyoCodess commented 6 months ago

@AyoCodess unfortunately no it's not particularly relevant. It's a separate way of loading environment variables that works quite well. You may be able to use that method instead of this library altogether. I haven't tried it out myself though so if you do, please let me know! Thank you for confirming it's a devDependency. I'll check it off in your issue description. Do you have a env.d.ts file? If you have an example repo of this not working it helps me tremendously as I can pinpoint exactly where the issue may be :)

I'll create one.