From 85047c894b5294bdfee2e73e0734bd11f0fabd36 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 16 Oct 2025 10:41:00 +0900 Subject: [PATCH 1/2] docs: add note that bun's env loading behavior interferes with Vite's one (#20947) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> --- guide/env-and-mode.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/guide/env-and-mode.md b/guide/env-and-mode.md index 9953a204..0b22fea8 100644 --- a/guide/env-and-mode.md +++ b/guide/env-and-mode.md @@ -74,6 +74,12 @@ In addition, environment variables that already exist when Vite is executed have ::: +:::warning Bun users + +When using [Bun](https://bun.sh), be aware that Bun automatically loads `.env` files before your script runs. This built-in behavior loads environment variables directly into `process.env` and can interfere with Vite's feature, as it respects existing `process.env` values. See [oven-sh/bun#5515](https://github.com/oven-sh/bun/issues/5515) for workarounds. + +::: + Also, Vite uses [dotenv-expand](https://github.com/motdotla/dotenv-expand) to expand variables written in env files out of the box. To learn more about the syntax, check out [their docs](https://github.com/motdotla/dotenv-expand#what-rules-does-the-expansion-engine-follow). Note that if you want to use `$` inside your environment value, you have to escape it with `\`. From 572d8d78ae5ab7536eeb3c9143808414d0146fc9 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Fri, 17 Oct 2025 08:16:24 +0800 Subject: [PATCH 2/2] resolved conflict --- guide/env-and-mode.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/guide/env-and-mode.md b/guide/env-and-mode.md index 109a148d..9cbedcfb 100644 --- a/guide/env-and-mode.md +++ b/guide/env-and-mode.md @@ -74,17 +74,13 @@ Vite 总是会加载 `.env` 和 `.env.local` 文件,除此之外还会加载 ::: -<<<<<<< HEAD -此外,Vite 使用 [dotenv-expand](https://github.com/motdotla/dotenv-expand) 来扩展在 env 文件中编写的变量。想要了解更多相关语法,请查看 [它们的文档](https://github.com/motdotla/dotenv-expand#what-rules-does-the-expansion-engine-follow)。 -======= -:::warning Bun users +:::warning Bun 用户 -When using [Bun](https://bun.sh), be aware that Bun automatically loads `.env` files before your script runs. This built-in behavior loads environment variables directly into `process.env` and can interfere with Vite's feature, as it respects existing `process.env` values. See [oven-sh/bun#5515](https://github.com/oven-sh/bun/issues/5515) for workarounds. +使用 [Bun](https://bun.sh) 时,请注意 Bun 会在脚本运行前自动加载 `.env` 文件。此内置行为会将环境变量直接加载到 `process.env` 中,并且可能会干扰 Vite 的功能,因为它会遵循现有的 `process.env` 值。有关解决方法,请参阅 [oven-sh/bun#5515](https://github.com/oven-sh/bun/issues/5515)。 ::: -Also, Vite uses [dotenv-expand](https://github.com/motdotla/dotenv-expand) to expand variables written in env files out of the box. To learn more about the syntax, check out [their docs](https://github.com/motdotla/dotenv-expand#what-rules-does-the-expansion-engine-follow). ->>>>>>> 85047c894b5294bdfee2e73e0734bd11f0fabd36 +此外,Vite 使用 [dotenv-expand](https://github.com/motdotla/dotenv-expand) 来扩展在 env 文件中编写的变量。想要了解更多相关语法,请查看 [它们的文档](https://github.com/motdotla/dotenv-expand#what-rules-does-the-expansion-engine-follow)。 请注意,如果想要在环境变量中使用 `$` 符号,则必须使用 `\` 对其进行转义。