From 6244ac95693fe40cb56bdd2c8cad8a9acea6ab38 Mon Sep 17 00:00:00 2001 From: Deniz Date: Mon, 10 Jun 2024 11:01:49 +0300 Subject: [PATCH] fix(vite): Fix environment variable loading issue for Windows (#545) Co-authored-by: Luca Forstner --- packages/bundler-plugin-core/src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index a04b03fa..5680103a 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -85,7 +85,11 @@ export function sentryUnpluginFactory({ ); // NOTE: Do not use the dotenv.config API directly to read the dotenv file! For some ungodly reason, it falls back to reading `${process.cwd()}/.env` which is absolutely not what we want. const dotenvResult = dotenv.parse(dotenvFile); - process.env = { ...process.env, ...dotenvResult }; + + // Vite has a bug/behaviour where spreading into process.env will cause it to crash + // https://github.com/vitest-dev/vitest/issues/1870#issuecomment-1501140251 + Object.assign(process.env, dotenvResult); + logger.info('Using environment variables configured in ".env.sentry-build-plugin".'); } catch (e: unknown) { // Ignore "file not found" errors but throw all others