Docusaurus search plugin generating wrong URLs with double paths on GitHub Pages

I’m using Docusaurus with the @easyops-cn/docusaurus-search-local plugin for my documentation site. Everything works fine when I test it locally, but after deploying to GitHub Pages with a custom domain, I’m running into a weird issue.

The search functionality is creating URLs that have the path duplicated. For example, instead of getting https://mydomain.com/docs/guides/setup#configuration, the search results show https://mydomain.com/docs/guides/setup/docs/guides/setup#configuration.

This only happens in production on GitHub Pages. When I run npm start or build locally with npm run build and serve it, the search URLs are correct.

Has anyone dealt with this before? I’m also struggling to reproduce this locally, which makes it hard to debug and test potential fixes. Any suggestions on how to either fix the URL generation or reproduce the issue in my local environment would be really helpful.

I encountered a similar problem with deployment on GitHub Pages. The issue was related to the incorrect base path configuration in the search plugin settings. GitHub Pages serves content differently than local environments, which can lead to discrepancies in the path references. To resolve it, I adjusted the search plugin settings in docusaurus.config.js by adding hashed: false and indexDocs: true. It’s also essential to ensure that your deployment reflects the production build properly, as this could contribute to the path duplication issue.

This is definitely a baseUrl config issue. I hit the exact same problem deploying to GitHub Pages with a custom domain. The search plugin doubles up the path because it’s not handling baseUrl properly. Check your docusaurus.config.js - make sure baseUrl is set to ‘/’ since you’re using a custom domain. If it’s set to something like ‘/repository-name/’, that’s what’s causing the duplication. Also check that your url field matches your actual custom domain exactly. You’ll need to rebuild and redeploy after changing these. It works locally because the dev server handles paths differently than the static GitHub Pages deployment.

yea, i had that too! make sure ur baseUrl in docusaurus.config.js is set right. and try clearing ur cache after deploying, it helped me fix it!