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
.env file variables are cached #75
Comments
are you re-building between |
I'm using react-native run-ios, which reloads the code. Could be that babel modules are not reloaded until some code ts/js code changes. |
yeah unfortunately, you'll have to fully restart the script every time you change your |
I run |
Oh! I think I know what's wrong. This is one of the caveats about this package. For now, try this and let me know if that fixes it: rm -rf node_modules/.cache/babel-loader/* I also want to see if we can observe changes and clear the cache going forward like in this other babel plugin https://github.com/codemix/babel-plugin-closure-elimination/blob/master/src/index.js |
@goatandsheep Thank you! It eventually resolved the issue. Could you update the package? |
It will take time for me to figure it out. I'll update the security dependencies, but this feature will have to wait until next month unless someone can help me. |
I have same problem, but It cannot solve my problem |
Maybe a temp solution for updating package.json scripts:
|
Repost from zetachang/react-native-dotenv#70, after a lot of digging, I think this babel/babel#8497 is really what react-native-dotenv needs to get this fixed. Seeing as there is currently no way to tell babel that the .env file is a dependency requiring a new build react-native-dotenv cannot possibly get it to rebuild when the env file changes. I think I have a partial workaround though, changing metro.config.js to include: const crypto = require('crypto');
const fs = require('fs');
let hash = crypto.createHash('sha256');
hash.update(fs.readFileSync('.env'));
const cacheVersion = hash.digest('hex');
module.exports = { // eslint-disable-line import/no-commonjs
...
cacheVersion,
}; See: https://facebook.github.io/metro/docs/configuration#cacheversion This results in metro using the hash of the .env file as a cache key and therefore invalidates the cache when the env file changes. I don't believe this will work for live reloading, you would still need to restart react-native whenever the env or any files using it changes, but we've been running with this for some time and haven't had anymore env caching issues. This is particularly pressing for us because our CI agents build JS bundles for 3 different environments in an unpredictable order so any env caching between those could cause a production outage for us. But thankfully we haven't seen that for the last few months since doing this change. |
Looks like babel/babel#11741 might provide a proper solution here also? |
when I ran "rm -rf node_modules/.cache/babel-loader/*", got module not found error. I do not see .cache folder inside node_modules |
@TJTorola zetachang/react-native-dotenv#70 (comment) But when you cp or update your .env with new values before running your code push command you can pass the Example
after env swaps the new |
@kingdavidmartins Yeah, that works as well. My goal with hashing the |
@TJTorola anything we can do to the library to automatically do this? I'm happy to accept any PRs. I really want to resolve this. |
@goatandsheep I'm not sure, I don't think it can be properly fixed without babel/babel#11741 getting patched first. |
for expo users, |
this should help Possibile duplicate: zetachang/react-native-dotenv#24 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
npm start -- --reset-cache is the solution for this |
Another approach with embedding the reset unto run-* commands IOS: |
@goatandsheep I think this issue should be re-opened, and perhaps even pinned. This is not an issue with This issue can be reproduced by initializing a new React Native project with:
And then adding this dependency. Until |
@taylorkline HM... Sorry to hear about the continuing issues. What do you recommend we do? React native uses babel. If you have issues and it's not using babel loader but it's solved with this other yarn command that is also included in the readme, then isn't it solved? How can I help? |
Ah, I see. I had a misunderstanding. As it's currently written, the caveats section sounds like it only applies specifically to people who might have manually added a babel caching solution. Since this issue of caching applies to the majority of users, including anyone who adds this project to a new React Native project, I would really suggest adding something like: "You must clean the babel cache after each change to your environmental variables using up more prominently within the Thanks for hearing me @goatandsheep |
That's good feedback 👍 I'll try to improve the readme to clarify |
I have tried everything from |
please test the next version https://www.npmjs.com/package/react-native-dotenv/v/3.4.0 if I get 3 thumbs up from the post I'll publish this as the proper change |
@goatandsheep I've tested I will look into this in more detail, but perhaps you can spot the issue right away. This issue only seems to appear in the
|
@goatandsheep I'll try and take a look at that version sometime this or next week. |
Tested on 3.4.0 and the env are not updated without and switching between both this doesn't change the
my babel config
|
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/75 |
Thanks thats work for me!! |
Thanks. Thats work for me |
Nothing mentioned above seems to work for my expo project mixed up with react web stuffs |
None of the above solutions worked for me, and finally this works: zetachang/react-native-dotenv#24 (comment). And this is super annoying as if I have 10 files using the environment variable, I have to change all the files... |
None of the above solution worked for me, but I just found the cached files and removed them. First, to search where was the cached files (with expo, but you might be able to find them elsewhere without it) :
I then found it in
|
Man you save my day!!!! This works thanks. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
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/75 |
I'm still having the same problem |
still having issues on expo 45. Have tried every solution in here. |
Tried all solutions above and none worked for me. This nuke worked (as usual :)). Cheers! |
Having same issue in 2023 |
Hi @esphung issues specific to that environment no longer exist. Please open a new ticket explaining your setup |
.env changes are not propagated to code.
If you update .env, new values will not be detected until you change the file that imports the variables.
The text was updated successfully, but these errors were encountered: