-
Notifications
You must be signed in to change notification settings - Fork 65
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
Proposal: enable usage of envalid outside node-js by dropping the dependency on dotenv #30
Comments
Hmm... completely removing |
Cool idea, I would also like to see the library be environment-agnostic. Adding dotenv is a relatively recent change, but it does make things significantly more convenient for the primary use case (server-side env validation). So I definitely want to keep it in, but am very much open to an option to disable it for use cases like yours |
|
Thanks a lot for working on this :-) Unfortunately it doesn't work. I didn't actually try my suggestion (sorry), and it turns out that the packager of react-native somehow analyzes the code before it is packaged and will stumble on the inlined So the only solution I can think of right now is to completely remove the dependency. But I could understand if you don't want to do this. |
Ah that's right, I remember that gotcha from RN. Can you try latest master locally, but change |
Hehe, nice idea. Yes, I'll test it. I'm not at home today, so it will be tomorrow. |
Allright, I got it working, but it isn't nice. The require-calls work with const fs = require('f'+'s')
const dotenv = require('d'+'otenv') But then the next error occurs when So I see the following solutions:
Fixing Which option do you prefer? |
Conditionally requiring the reporter can probably be done. Since you can provide your own, this might be a good thing either way. I find it weird that react-native is so strict on process usage though. React has a widespread use of |
I just created a PR for |
Looks like the has-flag PR isn't going forward. I can see the maintainer's point– this is kind of a flaw with how react-native only partially stubs out the Since this looks like it'd be a pretty invasive change, I'd recommend forking envalid instead and removing the parts that are problematic with RN. If RN fixes this issue down the road, we can revisit making envalid work better with it. |
I think envalid can conditionally require chalk in order to make a workaround available |
Alright, I just created a fork with the changes required to get it working in react-native. The changes are minimal but the solution doesn't look nice. I just made a PR in case you want to pull it. Anyway, thanks for your support! |
I just created a new PR: barbogast#2 |
Hi,
I like the idea of envalid a lot and would like to use it in a react-native app.
Unfortunately
dotenv
doesn't work within the app since it tries to import thefs
module which isn't available in the app. I was able to solve this by using react-native-config to get the configuration object. Now I would like to use envalid to validate this configuration object. But since envalid importsdotenv
that's not possible right now.One solution would be to entirely remove the dotenv dependency from envalid. So instead of
users would have to call
The option
dotEnvPath
could then be removed.This change would allow the retrieval of the environment by arbitary libraries (like react-native-config) or even different sources (json-files, databases) without the implicit loading of the environment by dotenv.
Thanks
Ben
The text was updated successfully, but these errors were encountered: