From 1041b711a2eab23ce04a346705770be53d38a2b1 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 27 May 2020 23:17:19 -0400 Subject: [PATCH] Better NODE_ENV explanation --- errors/non-standard-node-env.md | 22 +++++++++++++++++----- packages/next/lib/constants.ts | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/errors/non-standard-node-env.md b/errors/non-standard-node-env.md index 7655a8874d1ab..238823e622dd1 100644 --- a/errors/non-standard-node-env.md +++ b/errors/non-standard-node-env.md @@ -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 diff --git a/packages/next/lib/constants.ts b/packages/next/lib/constants.ts index de1b816cf32c1..1d744b843eee2 100644 --- a/packages/next/lib/constants.ts +++ b/packages/next/lib/constants.ts @@ -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`