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

Remove Exception if imported var does not exist #27

Open charlesjohannisen opened 7 years ago

charlesjohannisen commented 7 years ago

Allows you to import { MY_VAR, MY_OPT } from 'react-native-dotenv' even if the var is not defined in the env file or if the env file doesn't exist. Throwing an exception removes the optional nature of an .env file. As mentioned in this issue rather give the dev the option to assign the variable conditionally: myconfig.MY_VAR = MY_VAR || 'default'

tusbar commented 6 years ago

@charlesjohannisen I’ve forked this package to allow for more options and fix issues like this one.

https://github.com/tusbar/babel-plugin-dotenv-import

It’ll let you do that with { allowUndefined: true }.

brunohkbx commented 5 years ago

@zetachang can we have this feature?

nicklayb commented 5 years ago

It would be really useful to have this feature

MarcoScabbiolo commented 5 years ago

@zetachang any reason not to merge this PR? This is a must have

zek commented 5 years ago

Can we please merge this feature?

chandlervdw commented 5 years ago

bump. This feature is critical for use with github actions.

pke commented 4 years ago

I think the repo is pretty much abandoned by this time :(

goatandsheep commented 4 years ago

There's a new repo and package babel-plugin-dotenv-import. Please reopen in the new repo

MarcoScabbiolo commented 4 years ago

Or just write your env variables to a environment.js file using a script that runs right before the bundler and import that file as a module anywhere in the application.

Having a package to do this not only adds an unnecessary dependency but it also messes up the metro bundler cache, meaning you have to use --reset-cache every time you change the environment while running the packager server. Unless you dive deep into metro to write some kind of Middleware, it will assume a module with the same version always exports the same thing and cache it thus using the environment of the first cached version even if you change it. It is a pretty sane and safe assumption by the way, and mandatory if you want any kind of cache of the node_modules folder.