From 2e3125e18063dd23080d380c93c1b709bb59e413 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Fri, 14 Apr 2023 21:46:24 +0800 Subject: [PATCH] Fix vercel edge private env vars (#6841) --- .changeset/blue-moons-cough.md | 5 +++++ packages/integrations/vercel/src/edge/adapter.ts | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 .changeset/blue-moons-cough.md diff --git a/.changeset/blue-moons-cough.md b/.changeset/blue-moons-cough.md new file mode 100644 index 000000000000..d27e3e48b6bc --- /dev/null +++ b/.changeset/blue-moons-cough.md @@ -0,0 +1,5 @@ +--- +'@astrojs/vercel': patch +--- + +Fix vercel edge private environment variables usage diff --git a/packages/integrations/vercel/src/edge/adapter.ts b/packages/integrations/vercel/src/edge/adapter.ts index 411717a4145e..a2e937987e26 100644 --- a/packages/integrations/vercel/src/edge/adapter.ts +++ b/packages/integrations/vercel/src/edge/adapter.ts @@ -85,6 +85,13 @@ export default function vercelEdge({ vite.ssr ||= {}; vite.ssr.target ||= 'webworker'; + + // Vercel edge runtime is a special webworker-ish environment that supports process.env, + // but Vite would replace away `process.env` in webworkers, so we set a define here to prevent it + vite.define = { + 'process.env': 'process.env', + ...vite.define, + }; } }, 'astro:build:done': async ({ routes }) => {