Unverified Commit aab1fff8 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Better NODE_ENV explanation (#13476)

After #12361, I've seen a few users ask "but why".

This PR updates the err.sh link to better explain the restriction.

It also provides an alternative!
parent bee8c31b
# Non-Standard Node_env
# Non-Standard NODE_ENV
#### Why This Error Occurred
In your environment you set a non-standard value for `NODE_ENV`.
Your environment has a non-standard `NODE_ENV` value configured.
Next.js automatically sets this environment value for you and also forces the correct value during bundling to ensure the bundles are optimized and code can be tree-shaken correctly.
This may be by accident, so if you're unaware where the value is coming from, check the following:
When you set a non-standard environment value like `staging` this causes inconsistent behavior since we override the value to the standard one during bundling e.g. `production` or `development`.
- The `.env*` files in your project, if present
- Your `~/.bash_profile`, if present
- Your `~/.zshrc`, if present
The greater React ecosystem treats `NODE_ENV` as a convention, only permitting three (3) values:
- `production`: When your application is built with `next build`
- `development`: When your application is ran with `next dev`
- `test`: When your application is being tested (e.g. `jest`)
Setting a non-standard `NODE_ENV` value may cause dependencies to behave unexpectedly, or worse, **break dead code elimination**.
#### Possible Ways to Fix It
Remove any custom `NODE_ENV` environment variables and let Next.js automatically set the correct value for you.
To fix this error, identify the source of the erroneous `NODE_ENV` value and get rid of it: Next.js automatically sets the correct value for you.
If you need the concept of different environments in your application, e.g. `staging`, you should use a different environment variable name like `APP_ENV`.
### Useful Links
......
......@@ -42,6 +42,6 @@ export const UNSTABLE_REVALIDATE_RENAME_ERROR =
export const GSSP_COMPONENT_MEMBER_ERROR = `can not be attached to a page's component and must be exported from the page. See more info here: https://err.sh/next.js/gssp-component-member`
export const NON_STANDARD_NODE_ENV = `You are using a non-standard "NODE_ENV" value in your environment. This creates inconsistencies in the project and is strongly advised against. https://err.sh/next.js/non-standard-node-env`
export const NON_STANDARD_NODE_ENV = `You are using a non-standard "NODE_ENV" value in your environment. This creates inconsistencies in the project and is strongly advised against. Read more: https://err.sh/next.js/non-standard-node-env`
export const SSG_FALLBACK_EXPORT_ERROR = `Pages with \`fallback: true\` in \`getStaticPaths\` can not be exported. See more info here: https://err.sh/next.js/ssg-fallback-true-export`
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment