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

Remove Exception if imported var does not exist #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

charlesjohannisen
Copy link

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
Copy link

tusbar commented Nov 23, 2017

@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

@zetachang can we have this feature?

@nicklayb
Copy link

It would be really useful to have this feature

@MarcoScabbiolo
Copy link

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

@zek
Copy link

zek commented Sep 6, 2019

Can we please merge this feature?

@chandlervdw
Copy link

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

@pke
Copy link

pke commented May 15, 2020

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

@goatandsheep
Copy link

goatandsheep commented May 21, 2020

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

@MarcoScabbiolo
Copy link

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