Replies: 1 comment
-
|
This seems like a genuine and potentially nasty bug. Can imagine a scenario where someone thinks they're playing with their dev database but they're actually using production and ends up causing costly damage. The docs clearly state that the .env.* file loaded is based off the current NODE_ENV var but that's not what's happening. There's no mention in the docs of the second At least one issue has been created for this, but ignored and auto-closed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
This is regarding how the current
@next/envhas some issues, and at the same time the headache I had with how there was little to nothing documented on the main webpage - unfortunately, there's no way to do general discussions here, so I've added this to the "Help" category.The "default" convention of environment variables is:
NODE_ENV, it can be over-ridden to development (default), production, staging and testAt present,
@next/envloads environment variables in a non-conventional way.next.js/packages/next-env/index.ts
Lines 136 to 146 in 126c226
The issue with the code is that:
a) Line 136 check if
process.env.NODE_ENVis 'test', line 137 setsmodeto 'test' if it is 'test' ,and line 143 checks if it is 'test'.isTestandmodeis used nowhere in the entire file - all of this could've been done by just removing line 136 and 137, and replacing${mode}with${process.env.NODE_ENV}b) the value of dev will most probably be set to something like:
by making the changes in point (a) and letting next/env do the decision for us by reading the
NODE_ENVvalue, there is no need to check for the samec) there isn't any way to provide a staging env, the changes provided in point (a) should be able to resolve this
We may also be able to remove dotenv, since NodeJS 20 and onwards supports env natively, and dotenv-expand may be accomplished through destructing.
Additional information
Example
-
Beta Was this translation helpful? Give feedback.
All reactions