-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Environment Variables in gatsby-config.js not working #3896
Comments
Hmm not sure actually :-( |
@pgegenfurtner Do you have an example repo you could share? |
I looked a bit into it. The problem is, that dotenv looks for a file named So you could do this
But buts works only in the prod environment ( Now it works as I expect, but I see it only as a workaround (At least the modified develop command) |
It sounds like a fix for this could be to modify I'm not sure what's best practise here.. Whether I'm happy to make a PR for this if @KyleAMathews approves 😀. It looks like a fairly straightforward change in |
@m-allanson ah yeah — we should do that 😄 we do force set NODE_ENV to production during builds so we should do the same for development. |
Well perhaps not force it during development. Just set it unless the user set something else. We have to have |
@pgegenfurtner With the latest version of gatsby-cli (1.1.39), |
Nice. |
Okay, I think this can be closed then |
Should note that
|
I had to change the filename from |
I just did the following...
|
gatsbyjs/gatsby#3896 process.env was returning undefined added a config object into require(dotenv) w/ path: env.process.env.NODE_ENV
* bug: process.env gatsbyjs/gatsby#3896 process.env was returning undefined added a config object into require(dotenv) w/ path: env.process.env.NODE_ENV * updated: module.css => module.scss <HomePage /> & <StudySetOption /> * updated: module.css => module.scss rest of components using scss modules stage: structure for new <LandingPage /> created and being renederd in src > pages > index.js * updated: <LandingPage /> w/ scss added: Google fonts 1. Bold = Permanent Market 2. Medium = Mansalva 3. Light = Indie Flower * cleaned: removed all build warnings * SCSS: overall app styling update & debugging boarders removed * touchUps: variables for border-radius & transform rotation
Description
I want to use environment variables in my frontend code and in my gatsby-config.js. I followed the steps from https://www.gatsbyjs.org/docs/environment-variables/ and for the frontend code it works perfectly with my two files:
.env.development
and.env.production
.Environment
Gatsby version: 1.9.183
Node.js version: 8.9.4
Operating System: macOS 10.13.3
File contents (if changed):
gatsby-config.js
:package.json
: not changedgatsby-node.js
: not changedgatsby-browser.js
: not changedgatsby-ssr.js
: not changedActual result
process.env.GA_KEY
is undefiendExpected behavior
process.env.GA_KEY
is the value from my .env fileAm I doing something wrong here? I've read the documentation (gatsby and dotenv) multiple times and can't find the part which is wrong.
Thanks!
The text was updated successfully, but these errors were encountered: