-
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
GATSBY_ACTIVE_ENV vs. NODE_ENV – confusion #13304
Comments
This may be a duplicate of #13273, or at the very least share a root cause. |
Yeah it's a bug and indeed a duplicate of #13273. I'm closing it in favor of that issue. I have a PR up that fixes it. I also added a test. |
@wardpeet Great, thanks so much for the quick turnaround on this! A little disappointed I didn't get to fix it myself, but happy to see it fixed! I'm sure I'll find other opportunities in the future. Looking forward to this getting released. |
Oh my bad, will keep it open next time. |
Summary
As of #10565 Gatsby supports overriding the default
NODE_ENV
by specifying aGATSBY_ACTIVE_ENV
environment variable. This is exactly the functionality I wanted when I was figuring out how to load my app's.env.{env name}
config files into the gatsby build. However, now my build is breaking at runtime (seeing the same error as in #8285) because the webpack define plugin is getting the value ofGATSBY_ACTIVE_ENV
asprocess.env.NODE_ENV
instead of theNODE_ENV
set by callinggatsby build
. It seems like whatever is set forGATSBY_ACTIVE_ENV
should not replace theNODE_ENV
value originally set by gatsby, right?Steps to Reproduce
Run
gatsby serve
withGATSBY_ACTIVE_ENV=staging
, then try to hit one of your pages, you should see an error inloader.js
saying thatsyncRequires.components
is undefined.Expected Behavior
When running
gatsby build
orgatsby serve
,process.env.NODE_ENV
should beproduction
, regardless of the value specified forGATSBY_ACTIVE_ENV
. This behavior is what I expected based on my interpretation of the docs which say:It sounds like I should never be able to change
NODE_ENV
no matter what I pass, yet clearly I can.Happy to open a PR fixing this issue (and maybe cleaning up the docs a bit to clarify the use of
GATSBY_ACTIVE_ENV
& autoloading.env
). I just want to make sure that the issue I'm noticing is actually a bug and not the intended behavior first.The text was updated successfully, but these errors were encountered: