react-native-dotenv icon indicating copy to clipboard operation
react-native-dotenv copied to clipboard

Remove Exception if imported var does not exist

Open charlesjohannisen opened this issue 7 years ago • 9 comments

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'

charlesjohannisen avatar Oct 09 '17 09:10 charlesjohannisen

@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 }.

tusbar avatar Nov 23 '17 18:11 tusbar

@zetachang can we have this feature?

brunohkbx avatar Feb 14 '19 05:02 brunohkbx

It would be really useful to have this feature

nicklayb avatar Mar 14 '19 19:03 nicklayb

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

MarcoScabbiolo avatar Sep 03 '19 20:09 MarcoScabbiolo

Can we please merge this feature?

zek avatar Sep 06 '19 20:09 zek

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

chandlervdw avatar Oct 08 '19 17:10 chandlervdw

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

pke avatar May 15 '20 09:05 pke

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

goatandsheep avatar May 21 '20 19:05 goatandsheep

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.

MarcoScabbiolo avatar May 22 '20 05:05 MarcoScabbiolo