File tree 2 files changed +12
-0
lines changed
packages/astro/src/core/preview
2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change
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 ` .
Original file line number Diff line number Diff line change
1
+ import fs from 'node:fs' ;
1
2
import { createRequire } from 'node:module' ;
2
3
import { fileURLToPath , pathToFileURL } from 'node:url' ;
3
4
import type { AstroInlineConfig , PreviewModule , PreviewServer } from '../../@types/astro.js' ;
@@ -34,6 +35,12 @@ export default async function preview(inlineConfig: AstroInlineConfig): Promise<
34
35
await runHookConfigDone ( { settings : settings , logger : logger } ) ;
35
36
36
37
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
+ }
37
44
const server = await createStaticPreviewServer ( settings , logger ) ;
38
45
return server ;
39
46
}
You can’t perform that action at this time.
0 commit comments