Skip to content

Commit 308a327

Browse files
feat(env): upgrade dotenv (#38481)
Upgraded dotenv to v16. Breaking changes are: - Multiline parsing support - Support inline comments - Backtick support [See their changelog](https://github.com/motdotla/dotenv/blob/master/CHANGELOG.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 - [x] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` Co-authored-by: Balázs Orbán <[email protected]>
1 parent 24a1466 commit 308a327

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

docs/02-app/01-building-your-application/07-configuring/03-environment-variables.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,24 @@ export async function getStaticProps() {
4848

4949
<AppOnly>
5050

51-
This loads `process.env.DB_HOST`, `process.env.DB_USER`, and `process.env.DB_PASS` into the Node.js environment automatically allowing you to use them in [Route Handlers](/docs/app/building-your-application/routing/route-handlers).
51+
> **Note**: Next.js also supports multiline variables inside of your `.env*` files:
52+
>
53+
> ```bash
54+
> # .env.local
55+
>
56+
> # you can write with line breaks
57+
> PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
58+
> ...
59+
> Kh9NV...
60+
> ...
61+
> -----END DSA PRIVATE KEY-----"
62+
>
63+
> # or with `\n` inside double quotes
64+
> PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nKh9NV...\n-----END DSA PRIVATE KEY-----\n"
65+
> ```
66+
67+
> **Note**: If you are using a `/src` folder, please note that Next.js will load the .env files **only** from the parent folder and **not** from the `/src` folder.
68+
> This loads `process.env.DB_HOST`, `process.env.DB_USER`, and `process.env.DB_PASS` into the Node.js environment automatically allowing you to use them in [Route Handlers](/docs/app/building-your-application/routing/route-handlers).
5269
5370
For example:
5471
@@ -180,3 +197,9 @@ For example, if `NODE_ENV` is `development` and you define a variable in both `.
180197

181198
- If you are using a [`/src` directory](/docs/app/building-your-application/configuring/src-directory), `.env.*` files should remain in the root of your project.
182199
- If the environment variable `NODE_ENV` is unassigned, Next.js automatically assigns `development` when running the `next dev` command, or `production` for all other commands.
200+
201+
## Version History
202+
203+
| Version | Changes |
204+
| -------- | --------------------------------------------- |
205+
| `v9.4.0` | Support `.env` and `NEXT_PUBLIC_` introduced. |

packages/next-env/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
"devDependencies": {
3232
"@vercel/ncc": "0.34.0",
33-
"dotenv": "10.0.0",
34-
"dotenv-expand": "8.0.1"
33+
"dotenv": "16.3.1",
34+
"dotenv-expand": "10.0.0"
3535
}
3636
}

pnpm-lock.yaml

Lines changed: 11 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)