Skip to content
This repository was archived by the owner on Jul 8, 2020. It is now read-only.

Remove Exception if imported var does not exist#27

Open
charlesjohannisen wants to merge 1 commit into
zetachang:masterfrom
madeagency:master
Open

Remove Exception if imported var does not exist#27
charlesjohannisen wants to merge 1 commit into
zetachang:masterfrom
madeagency:master

Conversation

@charlesjohannisen

Copy link
Copy Markdown

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

tusbar commented Nov 23, 2017

Copy link
Copy Markdown

@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

Copy link
Copy Markdown

@zetachang can we have this feature?

@nicklayb

Copy link
Copy Markdown

It would be really useful to have this feature

@MarcoScabbiolo

Copy link
Copy Markdown

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

@zek

zek commented Sep 6, 2019

Copy link
Copy Markdown

Can we please merge this feature?

@chandlervdw

Copy link
Copy Markdown

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

@pke

pke commented May 15, 2020

Copy link
Copy Markdown

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

@goatandsheep

goatandsheep commented May 21, 2020

Copy link
Copy Markdown

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

@MarcoScabbiolo

Copy link
Copy Markdown

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants