-
Notifications
You must be signed in to change notification settings - Fork 99
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
Search API using Next.js: Failed to load Pagefind metadata #482
Comments
I also tried outputting the search bundle into my static assets folder via My guess is that the Next bundler resolves dynamic imports differently than in the Astro example with a vanilla script tag, so I tried swapping out the dynamic import for a static import. That breaks the build, throwing |
I realized my approach was a bit different than the one in the docs (and Astro example). I thought I should (1) build my static site bundle, (2) generate my pagefind search bundle and output it to my static asset dir So if I remove that third step, I (hopefully) just need to know where to output the pagefind search bundle in the second step, although that isn't immediately obvious to me. For example, it looks like my development mock file
|
Hmm, I don't have experience piping Pagefind's scripts through a bundler — I usually exclude the import(/*webpackIgnore: true*/ '/pagefind/pagefind.js'); I don't know if there's a nice way to transitively target just the Let me know if there's anything that would help from Pagefind's side. I have been wanting to publish a wrapper around the search JS as a npm package, so this might be a good prompt to do so. I need to do some research first on how to reliably make that wrapper bundler-friendly around a dynamic import. |
Thanks for getting back to me, @bglw! I'll try your suggestion of telling webpack to ignore the search bundle. An npm package for the search JS would be handy, but in the meantime hopefully I'll get this working and feel more comfortable with bundlers as a result 🙂 |
Worked like a charm — thank you, @bglw! PR updated with a preview deployment showcasing the snappy search. Now I just need to cobble together a UI and ship it, then I'll write up a blog post in case anyone else is keen on using Pagefind with Next.js. |
Awesome! Looking forward to it — ping me when a post is out and I'll add it to the resources page 🙂 |
Hi, I am excited about Pagefind — thanks for creating it!
Note: I originally asked this on Discussions (#481). If it's not an appropriate issue (because it's a me issue not a pagefind issue), I'd be glad to take this down!
The error
I am running into a
Failed to load Pagefind metadata
error when initializing the Pagefind Search API in this PR.Pagefind throws the error in this fetch call. The browser adds info:
Not allowed to load local resource: file:///my/path/to/pagefind/pagefind-entry.json?ts=1697986568739
. How can I ensure that fetch points to my client-side bundle rather than trying to fetch a local file path?More info
I see that the Search API exposes
bundlePath
andbaseUrl
options, but I haven't had success altering those. I also tried explicitly callingpagefind.init()
before.search()
, which leads to the same error.I also saw that a similar strategy works in Astro, so I'm hoping there's just a small piece I'm missing.
The text was updated successfully, but these errors were encountered: