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) {