I've somehow broken searching on my site

EDIT: Immediately after posting this, I thought of a workaround which has ‘fixed’ my site, but I would still value any thoughts as to how to fix this properly. The ‘fix’ was to add a /static/_redirects file with the single line; /search/undefined /search/index.json 302 and now search is back working.

Somewhere along the way, search has stopped working for my site.

Example: Search

Search for anything (eg, ‘Haytor’), this goes to

No results are returned, and console shows

https://dartmoorwalking.org/search/undefined
[HTTP/3 404  50ms]

Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

The same occurs if one enters a string in the Search widget, top-right, on any page.

However, if I enter the search string in the url; eg:

https://dartmoorwalking.org/search/haytor I get mixed results. A Not Found, but also a set of search results, so the index seems okay.

I believe the core issue is that the search page is somehow looking for the index.json at https://dartmoorwalking.org/search/undefined instead of https://dartmoorwalking.org/search/index.json but I can’t see how to fix this.

Help please?

The theme is Stack and I believe it was working okay at some point.

Hugo version: hugo v0.147.8-10da2bd765d227761641f94d713d094e88b920ae+extended windows/amd64 BuildDate=2025-06-07T12:59:52Z VendorInfo=gohugoio

Site source: GitHub - digdilem/dartmoorwalking.org: Website and code for dartmoorwalking.org

on your life site I clicked on search and got results after an input … anything changed?
when loading your site console shows

The resource https://dartmoorwalking.org/search/index.json was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.

guess not directly releated to your search index, but cloning your site failed when checking out master on Windows:

looks like these paths break the checkout:

  • resources/_gen/images/p/cox-tor-circular ← this one is also in your /public
  • resources/_gen/images/p/cox-tor-circular. ← DOT at the end
    and mybe related
  • cox-tor-circular.-rb-stones-gate-hanger-stone
  • cox-tor-circular.-rb-stones

that’s not easy to create on windows :wink:

mkdir mydir
mkdir mydir.
A subdirectory or file mydir. already exists.

so at least for me no easy way to check anything

Thanks for taking the time to take a look. I edited my original post within five minutes but I guess it was emailed out by then.

In summary, the problem was the 404 - " https://dartmoorwalking.org/search/undefined" I don’t know where Hugo is creating that url, and clearly “undefined” should be “index.json”.

I’ve made a temporary workaround by redirecting the url to the actual file in “/static/_resources” and as this is hosted on cloudflare pages, that has totally solved the problem to the user and explains why you couldn’t replicate it (Sorry about that)

But I’d still like to know how to fix this properly if you have any idea? It’s probably a theme bug, or something I’ve edited, rather than Hugo so perhaps I should be asking there.

(Thanks for the other fixes/recommendations too! The site was originally created on linux and migrated to dev on windows )