Reputation: 97
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.
Upvotes: 2
Views: 2141
Reputation: 21
My solution:
package.json
file://...
"scripts": {
"build": "npx astro build ./",
"build:node": "npx astro build ./ --node",
"preview": "npx astro preview --node",
//...
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,
//...
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
Upvotes: 2