Skip to content

Commit b8a6fa8

Browse files
bluwyematipicosarah11918
authoredJan 3, 2024
Error on preview if outDir missing (#9544)
* Error on preview if outDir missing * Update .changeset/four-moles-burn.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> --------- Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
1 parent ab6049b commit b8a6fa8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

‎.changeset/four-moles-burn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': minor
3+
---
4+
5+
Adds a helpful error for static sites when you use the `astro preview` command if you have not previously run `astro build`.

‎packages/astro/src/core/preview/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'node:fs';
12
import { createRequire } from 'node:module';
23
import { fileURLToPath, pathToFileURL } from 'node:url';
34
import type { AstroInlineConfig, PreviewModule, PreviewServer } from '../../@types/astro.js';
@@ -34,6 +35,12 @@ export default async function preview(inlineConfig: AstroInlineConfig): Promise<
3435
await runHookConfigDone({ settings: settings, logger: logger });
3536

3637
if (settings.config.output === 'static') {
38+
if (!fs.existsSync(settings.config.outDir)) {
39+
const outDirPath = fileURLToPath(settings.config.outDir);
40+
throw new Error(
41+
`[preview] The output directory ${outDirPath} does not exist. Did you run \`astro build\`?`
42+
);
43+
}
3744
const server = await createStaticPreviewServer(settings, logger);
3845
return server;
3946
}

0 commit comments

Comments
 (0)
Please sign in to comment.