Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: [astro preview] adapter does not have previewentrypoint

I've been making a website with astro (https://astro.build) and after some time, while running astro preview it errors. Here's my astro.config.mjs code:

import { defineConfig } from 'astro/config';
import vercel from '@astrojs/vercel/serverless';
import serviceWorker from 'astrojs-service-worker';

export default defineConfig({
    trailingSlash: 'ignore',
    output: 'server',
    adapter: vercel(),
    integrations: [serviceWorker()],
});

Any help would be appreciated.

error

like image 308
Zeptar Avatar asked Jan 24 '26 23:01

Zeptar


2 Answers

You can't preview the build of SSR adapters with astro preview, except the node adapter.

I'm quoting the docs

Since Astro 1.5.0, astro preview also works for SSR builds if you use an adapter that supports it. Currently, only the Node adapter supports astro preview.

like image 125
HappyDev Avatar answered Jan 26 '26 14:01

HappyDev


My solution:

  1. I adapt the scripts in the package.json file:
//...
"scripts": {
  "build": "npx astro build ./",
  "build:node": "npx astro build ./ --node",
  "preview": "npx astro preview --node",
//...
  1. I adapt the configuration in the astro.config.mjs file:
//...
import node from "@astrojs/node";
import vercel from "@astrojs/vercel/serverless";
    
let adapter = vercel();
    
if (process.argv[3] === "--node" || process.argv[4] === "--node") {
  adapter = node({ mode: "standalone" });
}
    
/**
 * Astro.js configuration.
 * @see https://astro.build/config
*/
export default defineConfig({
  output: "server",
  adapter: adapter,
//...
  1. Use the command npm run build:node to build locally and npm run preview. Vercel uses the npm run build command and employs its adapter.

You can see the example used in my repository

like image 44
Sergio Ridaura Avatar answered Jan 26 '26 13:01

Sergio Ridaura