-
-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pagefind Search Not Working with Vercel Adapter in Astro Starlight #2824
Comments
👋 Wanted to share a temporary workaround for this issue that worked for me. This is similar to the sitemap fix from #445. You can create a custom integration that copies the Pagefind files to the correct Vercel output directory after build: // pagefind-copier.ts
import type { AstroIntegration } from "astro";
import { promises as fs } from "node:fs";
import * as path from "node:path";
export function pagefindCopier(): AstroIntegration {
return {
name: "pagefind-copier",
hooks: {
"astro:build:done": async ({ logger }) => {
const buildLogger = logger.fork("pagefind-copier");
buildLogger.info("Copying pagefind files from dist to Vercel output");
try {
const distPath = "./dist/client";
const vercelPath = "./.vercel/output/static";
const pagefindSourceDir = path.join(distPath, "pagefind");
const pagefindDestDir = path.join(vercelPath, "pagefind");
await fs.mkdir(vercelPath, { recursive: true });
await fs.mkdir(pagefindDestDir, { recursive: true });
async function copyDir(src: string, dest: string) {
const entries = await fs.readdir(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
await fs.mkdir(destPath, { recursive: true });
await copyDir(srcPath, destPath);
} else {
await fs.copyFile(srcPath, destPath);
}
}
}
try {
await fs.access(pagefindSourceDir);
} catch (error) {
buildLogger.warn("No pagefind directory found in dist");
return;
}
await copyDir(pagefindSourceDir, pagefindDestDir);
buildLogger.info("Successfully copied pagefind directory to Vercel output");
} catch (error) {
if (error instanceof Error) {
buildLogger.error(`Error copying pagefind files: ${error.message}`);
} else {
buildLogger.error("An unknown error occurred while copying pagefind files");
}
throw error;
}
},
},
};
} Then add it to your Astro config as the last integration: import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import vercel from '@astrojs/vercel/static';
import { pagefindCopier } from './pagefind-copier';
export default defineConfig({
integrations: [
starlight({ /* ... */ }),
vercel(),
// Must be last in the list
pagefindCopier()
],
});
This workaround ensures the Pagefind files are copied to the correct location in Vercel's output directory, fixing the 404 errors for |
Hi @faiz9068! I think this should be fixed by withastro/adapters#508 which was just released in Could you try updating (you can run |
Thanks for testing — we’ll take a look |
OK, we diagnosed the issue and released a fix. I just tested and upgrading to |
@delucis v8.0.4 works great without the workaround, thank you! This is unrelated, but I'm still running with a local revert patch for |
Very much not in my wheelhouse unfortunately, but I’ll mention to folks that this is blocking for you! |
What version of
starlight
are you using?^0.31.0
What version of
astro
are you using?^5.1.1
What package manager are you using?
npm
What operating system are you using?
windows
What browser are you using?
chrome
Describe the Bug
Issue: Pagefind Search Not Working with Vercel Adapter in Astro Starlight
Description
When using Astro Starlight with the Vercel adapter, the built-in search functionality (powered by Pagefind) fails to work in production. The Pagefind route is not properly included in the final Vercel build output, resulting in 404 errors when attempting to use the search feature.
Steps to Reproduce
Current Behavior
/pagefind/pagefind.js
Expected Behavior
Environment
Possible Related Issues
Link to Minimal Reproducible Example
as
Participation
The text was updated successfully, but these errors were encountered: