Skip to content

Commit

Permalink
Better NODE_ENV explanation (#13476)
Browse files Browse the repository at this point in the history
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!
  • Loading branch information
Timer authored May 28, 2020
1 parent bee8c31 commit aab1fff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 17 additions & 5 deletions errors/non-standard-node-env.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
# 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

Expand Down
2 changes: 1 addition & 1 deletion packages/next/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`

0 comments on commit aab1fff

Please sign in to comment.