Troubleshooting: 502 Errors After Deleting or Moving Files
When you remove or move a file in Docusaurus, you might expect the sidebar to simply update. However, if that file is referenced elsewhere in your configuration (like the Navbar), the entire site build will fail, resulting in a persistent 502 Bad Gateway error and a container restart loop.
1. The "Dependency Trap"
The Problem
Docusaurus is not just a collection of markdown files; it is a compiled React application. References to files are often "hard-coded" in configuration files by their Document ID.
If you delete a file (e.g., knowledge/docusaurus/index.md) but your docusaurus.config.js still tries to create a Navbar link to it, the build engine will throw a fatal error.
Common Symptom
The Docker container starts, but logs show:
Error: Couldn't find any doc with id "knowledge/docusaurus/index" in version "current".
Because the build fails, the web server never starts, and Cloudflare/Nginx returns a 502 error.
2. Proper Way to Hide Sidebar Items (Safe Method)
If your goal is to remove an item from the Sidebar while keeping it active for the Navbar or other links, do not delete the file. Instead, use one of these three methods:
Method A: sidebar_class_name: hidden (Recommended)
This keeps the file fully functional but tells the sidebar generator to ignore it.
- Open the
.mdfile. - Add this to the frontmatter:
---
title: My Page
sidebar_class_name: hidden
---
- Restart the container.
Method B: unlisted: true (Docusaurus v3+)
This removes the page from the sidebar, sitemap, and search, but keeps the URL active.
---
unlisted: true
---
Method C: Move to _category_.json
If you are trying to hide an "Index" page that represents a folder, you can often achieve this by configuring the category itself to be "linked" rather than have a separate file.
3. How to Safely Delete a File
If you truly want a file gone from the system entirely, follow this strict 3-step sequence:
Step 1: Search for References
Before deleting my-file.md, search your codebase for its ID:
grep -r "my-file" /opt/docker-data/apps/docusaurus/site/
Step 2: Clean up docusaurus.config.js
Check these sections in your config:
- Navbar Items: Look for
docId: 'my-file'. - Footer Links: Look for
to: 'docs/my-file'.
Change these links to point to an existing document or remove the entry entirely.
Step 3: Delete and Restart
rm docs/my-file.md
sudo docker restart docusaurus
4. Recovery: What to do if the site is already down
If you deleted a file and the site is now returning 502:
Step 1: Identify the missing ID
Check the logs to see exactly which file Docusaurus is looking for:
sudo docker logs docusaurus | grep "Couldn't find any doc with id"
Step 2: Emergency Restore
Create a placeholder file at the expected path to satisfy the build:
# Example if "intro" was deleted
echo "# Placeholder" > /opt/docker-data/apps/docusaurus/site/docs/intro.md
Step 3: Restart and Clean Up
Restart the container. The site should come back up. Now you can properly update your docusaurus.config.js and delete the placeholder safely.
Troubleshooting Checklist
- Check Logs: Run
sudo docker logs docusaurus --tail 50. - Verify IDs: Does the ID in
docusaurus.config.jsmatch the file path? (e.g.,knowledge/test/doc.md-> ID:knowledge/test/doc). - Check Sidebars: If you use a manual
sidebars.js, ensure the deleted file is removed from there too. - Verify Extensions: Docusaurus expects
.mdor.mdx. Ensure you didn't accidentally rename a file to.txtor something else. - Rebuild Cache: If errors persist after fixing references:
sudo docker exec docusaurus rm -rf .docusaurussudo docker restart docusaurus
Summary Table: How to Remove Items
| Goal | Action | Risk |
|---|---|---|
| Hide from Sidebar only | Add sidebar_class_name: hidden | No Risk (Safe) |
| Hide from Search/Sidebar | Add unlisted: true | No Risk (Safe) |
| Remove from Site completely | Delete file + Update docusaurus.config.js | High Risk (Build may fail) |
| Remove Folder | Delete folder + Check recursive links | High Risk |