1

I was trying to load the API key from .env to my app.js in this way, iOS Bundling was completed, but Android Bundling failed. This is in an expo environment.

Here is the babel.config.js:

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ["babel-preset-expo"],
    plugins: [
      [
        "module:react-native-dotenv",
        {
          moduleName: "@env",
          path: ".env",
        },
      ],
    ],
  };
};

And I imported in this way import {TEST_KEY} from '@env'

But I get iOS Bundling complete 39ms Android Bundling failed 27ms Unable to resolve "@env" from "App.js"

enter image description here

AmerllicA
  • 29,059
  • 15
  • 130
  • 154
PDD123
  • 21
  • 2

1 Answers1

0

I know what I want to say isn't a kind of solution, but sometimes giving up some troubles could be a solution. I guess this react-native-dotenv has got critical issues. So I prefer to use react-native-config instead.

Follow the example:

import Config from 'react-native-config';

console.log(Config.API_BASE_URL);

// The above line will log the API_BASE_URL from .env file.

AmerllicA
  • 29,059
  • 15
  • 130
  • 154