Skip to content

Commit 3aa3e00

Browse files
authored
[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
1 parent bf210f7 commit 3aa3e00

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fix `import.meta.env.DEV` always being set to `true` when using Content Collections

packages/astro/src/content/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export async function loadContentConfig({
190190
settings: AstroSettings;
191191
}): Promise<ContentConfig | Error> {
192192
const contentPaths = getContentPaths({ srcDir: settings.config.srcDir });
193+
const nodeEnv = process.env.NODE_ENV;
193194
const tempConfigServer: ViteDevServer = await createServer({
194195
root: fileURLToPath(settings.config.root),
195196
server: { middlewareMode: true, hmr: false },
@@ -206,6 +207,9 @@ export async function loadContentConfig({
206207
return new NotFoundError('Failed to resolve content config.');
207208
} finally {
208209
await tempConfigServer.close();
210+
// Reset NODE_ENV to initial value
211+
// Vite's `createServer()` sets NODE_ENV to 'development'!
212+
process.env.NODE_ENV = nodeEnv;
209213
}
210214
const config = contentConfigParser.safeParse(unparsedConfig);
211215
if (config.success) {

0 commit comments

Comments
 (0)