zetachang / react-native-dotenv

A Babel preset let you import application configs from .env file (zero runtime dependency)
MIT License
915 stars 68 forks source link

Update README.md example does not add env #74

Closed kopax closed 4 years ago

kopax commented 4 years ago

Hello, I have tested to install on a fresh expo sdk 36 blank project the example :

 npm install react-native-dotenv metro-react-native-babel-preset --save-dev

I have created a .env file with:

API_KEY=lorem
ANOTHER_CONFIG=foobar

I edited babel.config.js with:

module.exports = function(api) {
  api.cache(true);
  return {
-    presets: ['babel-preset-expo'],
+    presets: ['babel-preset-expo',"module:metro-react-native-babel-preset", 'module:react-native-dotenv'],
  };
};

Env are not present in process.env, as a sample it look like:

{
  "NODE_ENV": "development",
  "PUBLIC_URL": "",
  "APP_MANIFEST": {
    "name": "blank-test",
    "slug": "blank-test",
    "privacy": "unlisted",
    "sdkVersion": "36.0.0",
    "platforms": []
  }
}

Thanks and best!

zRelux commented 4 years ago

Have you tried reading the docs? It clearly states that to access the env you need

import { API_KEY, ANOTHER_CONFIG } from 'react-native-dotenv' where API_KEY is in env

kopax commented 4 years ago

I have abandoned. Seems like this plugin does not fit for expo projects