5.8.10
Troubleshooting
Common search problems on Astro and EmDash, what causes each one, and how to fix it. Includes every build error the EmDash admin page shows.
Each problem below starts with what you see, then the cause and the fix. EmDash build errors and admin messages have their own section: EmDash build errors.
Both
The theme’s search opens instead of ours
Cause: the theme has its own search, and the plugin leaves it alone until you ask it not to. Takeover is off by default. Or the theme’s search is a custom button or popup that takeover cannot recognize.
Fix: turn on takeover (EmDash: Take over the theme’s search form on the Search admin page; embed: takeover.enabled). It works on a GET search form with a field named q and on EmDash’s LiveSearch box. If the theme’s form uses another field name, set Search input name to match. If the theme opens its own popup from a button, add one placement. Works with your theme has all three cases and a one-minute check.
The shortcut opens the theme’s search, not ours
Cause: with takeover off, every key press also reaches the theme’s own listeners. A theme script that binds Cmd+K to its header box (as EmDash’s blog template does) then opens its own search too.
Fix: turn on takeover. Our shortcut keys then win over the theme’s. A theme listener added before the search script ran can still see the press first. See Works with your theme.
The search results page shows two search fields
Cause: the results page draws its own search field, and the theme’s own field is still on the page outside it.
Fix: replace the body of the theme’s search page with <SearchResults> (EmDash) or the data-search-results mount (embed). Put the theme’s own form and list inside it. They show only when the script does not run. See The search results page.
“See all results” goes to the wrong page, or takeover does nothing
Cause: the results page URL does not match the theme’s search form action exactly. A form is taken over only when it is a GET form to that URL.
Fix: set Results page URL (EmDash) or results (embed) to the form’s action, trailing slash included. Check the other takeover conditions in Embed on any server: one field named like Search input name, and no other named fields except allowed hidden inputs.
A shortcut key I set does not work
Cause: Space cannot be a shortcut key. On a Mac, Ctrl records as ctrl, not mod. mod means Cmd on a Mac and Ctrl elsewhere.
Fix: pick another key, or type mod+k to get Cmd+K on a Mac and Ctrl+K on Windows and Linux.
Search does nothing in an old Safari
Cause: the dialog needs constructable stylesheets, which Safari added in 16.4.
Fix: nothing to fix. In those browsers, every search form and link stays native and goes to the results page.
Visitors see an old index after a deploy
Cause: the manifest, which names the current index files, is cached too long.
Fix: cache the hashed files for a year, and the manifest with max-age=0, must-revalidate. See Performance.
My Content Security Policy blocks the search
Cause: on Astro, Vite inlined the small SearchPage script because vite.build.assetsInlineLimit is set high.
Fix: lower that limit. Everything else is a file, so script-src 'self'; style-src 'self' works. See Performance.
Astro
Search is empty in astro dev
Cause: the html() source scans the built HTML, and the dev server builds none. In dev, html() gives no records. Collection records still work.
Fix: run astro build and astro preview to test pages that come from html().
The build fails with a list of URLs or anchors
Cause: after the build, every collection and html() record must point at a built page, and every section at an id the page renders. A url pattern that misses its route, or a page left out of getStaticPaths but not by filter, fails the build. This stops dead results.
Fix: set the collection’s url to match your route (for example blog: { url: "/posts/{slug}" }), or use filter to leave out the entries your route skips. With output: "server", these are warnings, not errors. See Install on Astro.
The build fails on a facet name
Cause: no source or index may name a facet type or q. The first is the content type, and the search page reads ?q= as the query.
Fix: rename the facet.
A pinned page or suggested link fails the build
Cause: each URL in pinned and suggested must be a canonical page URL in the index.
Fix: use the page’s exact URL, with your base and trailing slash. The dev server only warns, because it has no built pages.
A warning says a page has more than 20 keywords
Cause: a page keeps its first 20 keywords.
Fix: trim the list to the words people really search for.
EmDash
No search dialog opens on my site
Cause: the plugin prints its two tags only where the layout renders <EmDashHead> and <EmDashBodyEnd page={page} />. A hand-made layout may not.
Fix: open a public page, view its source, and look for data-search-config near the end of <body>. If it is not there, add <EmDashBodyEnd page={page} /> before </body>. The tags never print on preview or edit-mode pages, so check a public one. See Install on EmDash.
The admin page says “Not built yet”
Cause: the first build runs by itself within a minute of install, on EmDash’s cron. On Cloudflare, it never runs without EmDash’s Worker entry and a Cron Trigger every minute. It also waits while no collection has search turned on.
Fix: click Build now. On Cloudflare, add the Worker entry and the * * * * * cron, then run npx emdash doctor. Until the first build, the manifest answers 503 and the theme’s own search keeps working.
A change I published does not show in search
Cause: a change takes about a minute. The build runs once edits stop for 10 seconds, or at most a minute after the first edit. On Cloudflare without the cron, no change is picked up.
Fix: wait a minute, or click Rebuild now. Check the cron if changes never show. Drafts, scheduled entries, entries with seo.noIndex on, and entries with no public URL are never indexed.
A collection is missing from search
Cause: by default the plugin indexes every collection with search support that is routable and not hidden. A collection you list in collections that is not routable is left out with the build warning collection "<slug>" is not routable.
Fix: turn on search support for the collection in EmDash, or give it a public URL pattern.
A result links to the page, not the section
Cause: EmDash’s renderer prints no heading ids, so there are no heading results yet. Heading text is still searched.
Fix: none for now. Heading links are planned.
The Worker fails at start with a require error from postcss
Cause: EmDash’s HTML sanitizer pulls in postcss, and Vite 8 leaves its require calls to a shim that Workers lack.
Fix: add the small workers-require Vite plugin from Install on EmDash, with nodejs_compat on.
“Could not check the build. Trying again every 30 seconds.”
Cause: the admin page could not read the build’s status from the server.
Fix: nothing, in most cases. The page keeps trying. If it stays, reload the admin page and check the Worker’s logs.
“A build is already running. Your rebuild starts when it ends.”
Cause: you clicked Rebuild now while a build was running.
Fix: nothing. Your rebuild runs next.
The size badge is amber or red
Cause: the index is over 80% (amber) or 100% (red) of its gzip budget, 300 KB by default. This is a warning only. Search still works.
Fix: set a smaller clip, or index fewer collections. Or raise budget if the size is fine for your visitors. See Performance.
“This site has more than 5,000 pages, past the size this search is made for.”
Cause: every record loads into the visitor’s browser. Past 5,000 pages, the load on a phone gets slow.
Fix: search still works. To keep it fast, set a smaller clip or index fewer collections.
EmDash build errors
When a build fails, the admin page shows The last build failed with a message. The old index stays live, so search keeps working. One exception: no-collections. When no collection is left to index, the build takes the old index down too. The manifest then answers 503, and the theme’s own search works again, with takeover on as well. The server log has a line Search: the build failed (<code>): <message>, with one of these codes.
| Code | What you see | What it means | What to do |
|---|---|---|---|
plan-limit |
Your Cloudflare plan is too small for a search rebuild. The plugin needs the Workers Paid plan. | The build hit a Cloudflare Free plan limit: 50 D1 queries or 10 ms of CPU per run. | Move to Workers Paid. It fits about 11,000 pages per build. Node hosting has no such limit. |
interrupted |
The search build stopped before it finished 2 times in a row, most likely at a Cloudflare plan limit (D1 queries or CPU time). | Two builds in a row were cut off with no error of their own. | Same as plan-limit. If you are already on Workers Paid, check the Worker’s logs. Rebuild now tries again. |
no-collections |
No collection is set up for search. Add search support to a collection, then rebuild. | No collection has search support, or none of the listed collections can be indexed. |
Turn on search support for a collection in EmDash, or fix the collections option. Then click Rebuild now. |
too-large |
The “en” index is N bytes, N bytes over the 8000000-byte cap. Index fewer collections or set a smaller clip. | One locale’s index is over 8,000,000 bytes of JSON, the most a plugin route can send. | Set a smaller clip, or index fewer collections. |
deadline |
The build ran past 120 s; the next tick retries. | The build took over 2 minutes. | Nothing, usually. The next minute’s run tries again. If it keeps happening, index less. |
error |
The error’s own text. | Anything else, such as a database error. | Read the message and the server log. Click Rebuild now to try again. |
Two more codes stay in the server log and never fail the page: running (another build holds the lock, so this one waits) and lost-lease (another build took over, so this one did not publish). Both clear by themselves.
“The rebuild did not start”
Cause: the Rebuild now request failed, or the server answered with an unknown code. The text after it says why.
Fix: reload the admin page and try again. If it keeps failing, check that you are signed in with a role that can manage plugins, and read the server log.
“Could not load the search index” or “Could not load the settings”
Cause: the admin page could not read the plugin’s private routes.
Fix: click Try again. If it keeps failing, check the server log, and check that the plugin is in emdash({ plugins: [search()] }).