Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default import is not supported #113

Closed
2 tasks done
whalemare opened this issue Feb 1, 2021 · 6 comments
Closed
2 tasks done

Default import is not supported #113

whalemare opened this issue Feb 1, 2021 · 6 comments
Assignees

Comments

@whalemare
Copy link

  • Tried the troubleshooting Wiki
  • Followed the migration Wiki

Describe the bug
I was trying export all config keys as default, but have the next error:

src/config.ts: Default import is not supported
> 1 | import Environment from '@env';
    |        ^^^^^^^^^^^

To Reproduce
Code to reproduce the behavior:

import Environment from '@env';
export const config = assertEnvironment(Environment);

function assertEnvironment(config: any): MyTypedEnvironment {
  // some code for throw error if key not exists
}

Expected behavior
Expected that I can export all keys in one single const variable, to use it anywhere I want.

@goatandsheep
Copy link
Owner

Hi @whalemare unfortunately this is not something that is even potentially possible. Even the regular dotenv module does not work in this way. It has always been something you need to whitelist one variable at a time from process.env. if you really want, create an object and whitelist the attributes you put into it.

Are you trying to do error handling for this module? Maybe there's a misunderstanding.

@whalemare
Copy link
Author

Hi. Thank you for quick answer.
Yes, maybe error handling is unnecessary here.

@goatandsheep
Copy link
Owner

@whalemare lmk if you need any more help or if I can close this

@whalemare
Copy link
Author

We can close it, thank you

@tkodev
Copy link

tkodev commented May 9, 2022

Hi @whalemare unfortunately this is not something that is even potentially possible. Even the regular dotenv module does not work in this way. It has always been something you need to whitelist one variable at a time from process.env. if you really want, create an object and whitelist the attributes you put into it.

@goatandsheep dotenv seems to put all the variables into process.env without whitelisting.

The problem is when you're importing all env vars into a file. For my current production app, this is 50+ something variables (feature flags). With regular dotenv, I can access all vars under process.env and don't have to have 50+ lines in the import statement.

Is this something we can look into? (inserting vars into process.env)

@goatandsheep
Copy link
Owner

No not really possible to push something across all versions because it'll overwrite a lot of built in values from react and react native and stuff. This library used to not touch process.env at all (would still have lots of values). Now it adds to it whatever people ask. However for your own app you can look into the option to use allowList in your build options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants