-
-
Notifications
You must be signed in to change notification settings - Fork 48
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 variables are cached #422
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/422 |
Hi @AbdulBsit those Babel package versions are only really if you're using something overwrites the versions such as expo. Are you using expo? Also are the babel packages installed as dependencies or resolutions? Please tell me what else you tried that didn't work in the cacheing section of the README as I'm unable to reproduce this. |
Hey @goatandsheep Also things i have tried which not solves the issue
For your reference here is my current configurationpackage.json
babel.config.js
metro.config.js
|
I experience the same issue. |
same here |
api.cache(true) |
Having the same issue. Setting |
I come to my react native project root directory, run these command
it does work |
I am having the same issue. |
In my case, using a single quote instead of the double quote when importing the 'env' variable does not cause this problem. |
I don't think it does. Try changing the value in the variable and see if it picks it up. |
This is the one that worked for me #75 (comment) In my package.json
And I ran
(P.S. i'm just starting out front end development so don't laugh at what i just did ;)) |
This solved it for me. Says more about my experience with node than anything. Thank you for pointing this out! |
The problem in my case was Metro cache.
my
according to the docs it's "an arbitrary string appended to all cache keys in the project before they are hashed". Subsequent runs of the same env keep the cache, while switching between them seems to invalidate it. Hope it helps |
This is what worked for me in the resetCache: true |
Adding the resetCache: true to my metro.config.js worked. The final file is: const { getDefaultConfig } = require('expo/metro-config');
module.exports = (() => {
const config = getDefaultConfig(__dirname);
const { transformer, resolver } = config;
config.transformer = {
...transformer,
babelTransformerPath: require.resolve('react-native-svg-transformer'),
};
config.resolver = {
...resolver,
assetExts: resolver.assetExts.filter((ext) => ext !== 'svg'),
sourceExts: [...resolver.sourceExts, 'svg'],
};
config.resetCache = true; // ADDED IT HERE <<<
return config;
})(); But it was a nightmare until I found out about the caching. Probably this shouldn't be the default behaviour. |
Using |
The Having it only separated for each environment will make you face the same issues with the cache. |
You should concatenate all environment variables, so the cacheVersion changes together with any environment variable. Example module.exports = {
cacheVersion: [process.env.VAR1, process.env.VAR2, …].join(‘’)
} |
Shouldn't this be the default behavior? At least for the development variables. Should they be cached at all? |
I can confirm this happens with React Native CLI too (i.e. |
|
Setting We want to repeat : You might wanna change your .env settings easily without manual deleting of cache. But still want to keep your cache when your working on the same env |
when I trying with this I got the following error only. even after I change in the metro.config.js 'APP_ENV' is not recognized as an internal or external command, |
I'm only seemingly having this issue with my "Production" file. |
@mofolo this is a whole other issue unfortunately. If you're using |
@mofolo actually it occurred to me, what if you try in the config setting the name for {
"plugins": [
["module:react-native-dotenv", {
"envName": "REACT_APP_ENV"
}]
]
} |
@SulthanYS are you using Windows Powershell? to set environment variables in CLI, you need to do it differently
|
@jfbaraky you're right about the cache. it should be working and it isn't working. I just tested it now even with the package version resolutions. I worked with the babel team to try fix this. so i'm not sure why it's not working. Anyways, the solution is just to have to do |
this works for me |
Hi, the module import with version |
After scratching my head a lot the workaround i did is explained in this article updating and to update that i am calculating hash of env files and updating as required in a prestart script since i am working on windows my solution is mainly for that but i think it can be used on other platforms hope this helps!
|
I wonder, when the files change, it should already be picked up by the plugin, since it checks the modified time of each file? |
even using cacheVersion in metro.config does not work reliably. |
Describe the bug
I tried upgrading, dev dependencies releated to babel, but no luck, it cached the variable, until we change something in to the file we imported the "@env", when we undo the change, it goes back to cached value
Expected behavior
Change in .env should reflect in files, after a restart
Additional context
The text was updated successfully, but these errors were encountered: