From 3aa3e00a63b63ae443f824f11cffde2a194ea4bf Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Tue, 3 Jan 2023 09:45:38 -0500 Subject: [PATCH] [Content Collections] Fix `import.meta.env.DEV` always set to `true` (#5700) * fix: reset NODE_ENV on content config read * fix: move nodeEnv setter above createServer * chore: changeset --- .changeset/yellow-gifts-complain.md | 5 +++++ packages/astro/src/content/utils.ts | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 .changeset/yellow-gifts-complain.md diff --git a/.changeset/yellow-gifts-complain.md b/.changeset/yellow-gifts-complain.md new file mode 100644 index 000000000..f220d26c8 --- /dev/null +++ b/.changeset/yellow-gifts-complain.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix `import.meta.env.DEV` always being set to `true` when using Content Collections diff --git a/packages/astro/src/content/utils.ts b/packages/astro/src/content/utils.ts index 9017072ed..a3e7d4f99 100644 --- a/packages/astro/src/content/utils.ts +++ b/packages/astro/src/content/utils.ts @@ -190,6 +190,7 @@ export async function loadContentConfig({ settings: AstroSettings; }): Promise { const contentPaths = getContentPaths({ srcDir: settings.config.srcDir }); + const nodeEnv = process.env.NODE_ENV; const tempConfigServer: ViteDevServer = await createServer({ root: fileURLToPath(settings.config.root), server: { middlewareMode: true, hmr: false }, @@ -206,6 +207,9 @@ export async function loadContentConfig({ return new NotFoundError('Failed to resolve content config.'); } finally { await tempConfigServer.close(); + // Reset NODE_ENV to initial value + // Vite's `createServer()` sets NODE_ENV to 'development'! + process.env.NODE_ENV = nodeEnv; } const config = contentConfigParser.safeParse(unparsedConfig); if (config.success) {