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
Can't get multi env working #365
Comments
Hey, thank you for opening this issue! 🙂 To boost priority on this issue and support open source please tip the team at https://issuehunt.io/r/goatandsheep/react-native-dotenv/issues/365 |
So when you set app env in the bash profile your process env prints the correct value for app env? Sorry I'm just trying to understand what happened here. I'm trying to figure out if it's a issue with how the env var was set https://www.npmjs.com/package/dotenv-flow#node_env--specific-env-files Or if it's being overwritten somehow? Or it's another caching issue? (this will be worked on next week!!) Or something else? |
Yes. When I set the APP_ENV in bash profile it correctly prints the values of correct .env file and I see APP_ENV is one of the I even tried with a different name e.g. MY_APP_ENV by changing the envName in the babel.config.js and running To make sure anything not cached I set Also, If I run other scripts those gets APP_ENV correctly. test.js
When I run |
Ok I see now. I'll make sure to test the specific command |
I'm facing the same problem, as per #385 discussion. Any update on this? I thought I missed something obvious since it seems like it just works for others. And the questions are for edge cases. |
Hi I tried this in my test project and without caching resolved, it failed to work correctly, but with it resolved it worked correctly. To resolve caching issues, please ensure that you are using react-native-dotenv 3.4.2 or later and if the following PR is not closed ( expo/expo-cli#4593 ) you will need to add the following to your package.json: "resolutions": {
"@babel/core": "^7.20.2",
"babel-loader": "^8.3.0"
} This will be added to the README soon. If it is closed, please make sure to update expo and expo webpack config to whatever version that has been released unto. If the above suggestions do not work let me know and we will continue investigating. |
I'm facing the exact same issue even when I add these |
Hey guys, I've found sort of a solution (honestly, I don't know if it should be categorized as such). But, I tried:
And none worked for me. What actually worked was executing So, setting it with the env we want actually spawns a new Metro instance with the Edit: |
Hi @Victor-ARC thank you so much for this. I have not been able to reproduce this issue but if you have a reproduction instance I'd really appreciate it so i can update the documentation or tweak the code to figure out why this is happening and fix it. I'm sorry, it shouldn't be this difficult to use. |
Hi @goatandsheep But, technically, you should just need a basic RN app and try to add the RN-dotenv lib. Maybe you could try doing this on a different machine than yours? My guess is that your usual machine is already set with the variables and stuff. Could be that this happens because we're not in your environment and thus our Metro instance can't communicate with the |
I know this issue has been marked as closed, but it's the exact problem I am facing.
But will get passed down when running I don't think the problem is with this lib, it feels like its more about how you set the |
Same here.
But starting the packager and running the app separately, like so:
Doesn't do the trick. Instead of picking up the passed down NODE_ENV, it defaults to .env (or the .development one). |
Hello there. It seems the issue is still happening (I can't get my app building with 3 different .env files) but the issue was closed without a solution, right? In my case, I have .env, .env.staging and .env.production. I can get the app to load .env and .env.production, but not the .env.staging. Any tips on this one? |
Any solution? |
Hi sorry I don't know what the problem is but I'm confident if you tell me what you've tried I can get you a solution. Unfortunately you can't use a snack because snack doesn't let you install devDependencies and this library pretty much only works as a devDependency. If you tell me the exact line you're using to run your code I can help you :) For example, @fellenabmb used
you only need to use the Also, I'm noticing the toolchains are more robustly overwriting the value of
I hope that helps for now! |
Describe the bug
I have multiple env files,
I use the command
APP_ENV=staging npx react-native run-ios
to run the app. But the I get undefined when accessing variablesTo debug the issue I added a console log here
react-native-dotenv/index.js
There is no APP_ENV variable in process.env
I followed the documentation correctly and unable to figure out why APP_ENV not being passed.
For the moment I'm setting APP_ENV as a global env variable in .bash_profile and it works fine.
To Reproduce
Steps to reproduce the behavior:
APP_ENV=staging npx react-native run-ios
Expected behavior
Correct environment variables should be set
Screenshots
If applicable, add screenshots to help explain your problem.
Dev environment (please complete the following information):
The text was updated successfully, but these errors were encountered: