🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Fundamentals••By Komal Nakrani

astro preview vs astro dev: Which One to Run

astro preview serves your built dist/ folder the way production will; astro dev runs a hot-reloading dev server. When to use each, flags, background mode and errors.

#Astro#astro preview#CLI#Deployment

astro preview starts a local server that serves your built site from dist/, so you can check exactly what will be deployed. astro dev compiles pages on request with hot reload while you work. Use astro dev for building, and run astro build followed by astro preview before you deploy, because bugs from minification, prerendering or missing files only show up in the build.

Key Takeaways

  • astro preview doesn’t build. Run astro build first or it fails with “The output directory … does not exist”.
  • Both servers default to http://localhost:4321.
  • Server-output sites need an adapter that supports preview, such as @astrojs/node.
  • Astro 7 adds --background plus stop, status and logs subcommands for preview servers.

astro dev vs astro preview

astro dev astro preview
Serves Source files, compiled on request The built output in dist/
Hot reload Yes No; rebuild to see changes
Speed of first load Slower, pages compile on demand Fast, files are prebuilt
Dev toolbar and error overlay Yes No
HTML compression, bundling, hashed assets No Yes, same as production
getStaticPaths() runs Per request Already ran during the build
Use it for Writing code Checking the final site before deploy

The pre-deploy check

# terminal
npm run build
npm run preview

Open http://localhost:4321 and look for problems that astro dev hides:

  • Build-only failures. Data fetched in getStaticPaths() or frontmatter at build time can differ from what you saw in dev, for example when an environment variable is only set locally.
  • Whitespace changes. Astro 7’s compressHTML: 'jsx' default can remove spaces between inline elements on separate lines.
  • Broken asset paths. A string path like /src/assets/logo.png loads in dev, because Vite serves source files, but 404s after the build. Import the file or move it to public/.
  • Redirects and 404 pages. Static redirects become meta-refresh pages; your 404.astro is served for unknown URLs.

Flags

# terminal
npx astro preview --port 8080 --host --open
Flag What it does
--port <n> Port to listen on (default 4321)
--host Listen on all addresses, so phones on your network can open it
--host <address> Listen on a specific network address
--open Opens the browser when the server starts
--allowed-hosts Comma-separated hostnames to allow, useful behind a tunnel

Background preview servers in Astro 7

Astro 7 can run the preview server in the background and track it with a lock file:

# terminal
npx astro preview --background
npx astro preview status
npx astro preview logs --follow
npx astro preview stop

If a preview server is already running for the project, a second astro preview reports “Another astro preview server is already running” with its URL and PID. Pass --force to replace it, or --ignore-lock to start another one alongside it that stop, status and logs won’t track. The two flags can’t be combined.

When Astro detects that an AI coding agent launched the command, it starts the preview server in the background automatically on supported platforms, so the agent’s terminal isn’t blocked.

Preview with server output

For a fully static site, astro preview uses a built-in static file server. If any route is rendered on demand, preview runs the adapter’s own preview server instead. Not every adapter has one; if yours doesn’t, you get:

[preview] The <name> adapter does not support the preview command.

@astrojs/node supports preview. For hosts whose adapters don’t, use the host’s own local tooling, for example wrangler pages dev ./dist for Cloudflare Pages. If you see [preview] No adapter found., your config has server output but no adapter; the no adapter installed fix covers it.

Every Komal theme builds to static files, so npm run build && npm run preview shows you exactly what Cloudflare Pages, Netlify or Vercel will serve. Our static hosting docs and the Cloudflare deploy guide take it from there, and every Astro CLI command lists the rest of the CLI. If you’re starting a new site, browse Astro themes. The astro preview CLI reference has the full flag list.

FAQ

What is the difference between astro dev and astro preview?

astro dev compiles pages on request with hot reload for development. astro preview serves the already-built dist/ folder, so it shows what production will look like.

Does astro preview rebuild my site?

No. It only serves the existing build. Run astro build again after every change you want to see in preview.

Can I use astro preview in production?

It isn’t meant for production. Deploy dist/ to a static host, or use your adapter’s production server, such as the standalone Node.js server from @astrojs/node.

Why does astro preview say the output directory does not exist?

You haven’t built the site yet, or outDir points elsewhere. Run npm run build, then npm run preview.