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
plugin works only once #13
Comments
Hey thanks for reporting this, I think you are experiencing caching issues, when you change the environment variables you have to clear out your cache. Unless you are saying that the variables aren't getting set at all. |
Hey Brian,
Yep, that’s what I’m saying, the variables are set at the first run but as soon as my node server reloads itself (nodemon) or I restart it myself (same behavior for dev run or prod build btw) the variables aren’t set at all anymore.
—
Richard
… On 12 Apr 2018, at 16:01, Bryan Goldstein ***@***.***> wrote:
Hey thanks for reporting this, I think you are experiencing caching issues, when you change the environment variables you have to clear out your cache.
Unless you are saying that the variables aren't getting set at all.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Hmm... Could it be hot loading? If the process that watches your changes didn't have the environment variables set maybe that would do it? I'm not sure how to test this hypothesis. |
@brysgo I thought about it but it seems unlikely, the fact env variables get unset is really random, either while the dev server is running (and reloading) or when running several prod builds in a row. Maybe I did something wrong but I'm clueless here. If you want you can give it a try with this repo : https://github.com/sylv3r/react-starter |
am facing a bit different problem i actually followed nextjs example on with dot-env which uses this plugin |
btw removing node_modules and reinstall them again seems to solve the issue |
@FadiAboMsalam - Unfortunately the transformed code is cached with the old variable values. You can remove just the cache (which is likely stored inside your node_modules folder in some cache dotfiles), but I would love to find a better solution to this! |
## Issue I decided to rewrite the [with-dotenv](https://github.com/zeit/next.js/tree/canary/examples/with-dotenv) using [dotenv-webpack](https://github.com/mrsteele/dotenv-webpack) example because: - changes doesn't get applied (#4748, brysgo/babel-plugin-inline-dotenv#13) - the production mode doesn't work at all - this approach has already been used in the [examples/relay-modern](https://github.com/zeit/next.js/blob/9320d9f006164f2e997982ce76e80122049ccb3c/examples/with-relay-modern/next.config.js) - it is [documented](https://webpack.js.org/plugins/environment-plugin/#dotenvplugin) by webpack ## Alternatives * remove/deprecate example * fix babel-plugin-inline-dotenv ## Related Closes: #4748
same problem. When I run nodemon -w src --exec \"babel-node src/bin/www --presets es2015,stage-0\" the first time it set env correctly. When I restart the server I see the env in the process.env but seems that babel not applies them to the project. Any suggestions? |
@andreametelli - you might be experiencing caching issues, make sure you don't have any cache directory set, and if you do, delete it |
@brysgo I already deleted my cache. I noticed that using nodemon with babel-node the plugin loads the configuration only if I save the main file of my project also if I didn’t modified it. If I save an other file nodemon restarts correctly but without load the config. |
@andreametelli - interesting, could nodemon + babel-node be running the babel plugin from a different path? |
@brysgo I don’t think so, because i usually work without es6 modules. It was my first experience with them. Usually using nodemon with node command i can save any file and nodemon restarts the application correctly also loading all the configuration from dotenv. Using babel-node the behavior is different. As i told before, when i save a file that is not the main file it will restart without loading the specific envs. |
Any update on this? |
@brunohkbx - I'm not really sure how to triage this, but if you have any thoughts I'm all ears. |
For react-native folks: you should clear Metro cache (restart it with Shift+R) after changing .env file. |
For those stumbling on this: Disabling the babel cache prevents cached env values, but will increase build times. For my small project this is negligible and babel is still ⚡ Try running |
Once installed the plugin works as expected (loading my
.env
vars inprocess.env
being used in webpack and all), but after a node reload or any changes, it suddenly stops to populateprocess.env
.I can make it to "work" again either by changing in
.babelrc
thepath
option value (which I should not need, my.env
is at the root of my repository) or by running a newyarn install --dev babel-plugin-inline-dotenv
to clean it up, which makes me wondered if there's some sort of cache messing up here ?Once it stops working for a specific
.env
path, it won't use it again no matter what until reinstalled.node version : 9.11.1
package.json
(relevant part).babelrc
The text was updated successfully, but these errors were encountered: