Skip to content
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

Better NODE_ENV explanation #13476

Merged
merged 2 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`