From 2e1740bb69d2bffdb08da4541b23b9e12daed757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Sun, 22 May 2022 18:57:55 +0200 Subject: [PATCH] docs: clarify environment variables behavior (#36620) Based on https://github.com/vercel/next.js/issues/36551#issuecomment-1113457752 making the docs more clear which also aligns with the wording of Environment Variables in Middlerware: https://nextjs.org/docs/api-reference/next/server#how-do-i-access-environment-variables See also: https://github.com/vercel/next.js/pull/20869#issuecomment-757799953 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com> --- docs/basic-features/environment-variables.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/basic-features/environment-variables.md b/docs/basic-features/environment-variables.md index 7f9d7d70e914..d68a614627ed 100644 --- a/docs/basic-features/environment-variables.md +++ b/docs/basic-features/environment-variables.md @@ -46,8 +46,7 @@ export async function getStaticProps() { } ``` -> **Note**: In order to keep server-only secrets safe, Next.js replaces `process.env.*` with the correct values -> at build time. This means that `process.env` is not a standard JavaScript object, so you’re not able to +> **Note**: In order to keep server-only secrets safe, environment variables are evaluated at build time, so only environment variables _actually_ used will be included. This means that `process.env` is not a standard JavaScript object, so you’re not able to > use [object destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment). > Environment variables must be referenced as e.g. `process.env.PUBLISHABLE_KEY`, _not_ `const { PUBLISHABLE_KEY } = process.env`.