While running bun dev, /blog/ returned 404, but /en/blog/ rendered correctly.
The final cause was not routing configuration, but a directory-name collision.
Symptoms
http://localhost:4321/blog/returns 404http://localhost:4321/en/blog/works- Production build (
bun run build) still generates/blog/index.html
What I Suspected First
I first suspected link and locale path generation.
- Is
href: "/blog"inHeaderNavbroken? - Is
getLocalePath()behaving incorrectly only for Japanese? - Is
/blogremoved byprefixDefaultLocale: falsebehavior?
None of those were the problem.
Verification Process
I validated facts in this order:
- Check static output
bun run buildlogs include/blog/index.htmldist/blog/index.htmlactually exists
- Check rendered links
- Nav link in
dist/index.htmlis"/blog/" - Nav link in
dist/en/index.htmlis"/en/blog/"
- Nav link in
- Check i18n behavior
- With
prefixDefaultLocale: false, Japanese should be/blog/ /ja/blog/being 404 is expected
- With
At this point, route definition and link generation were confirmed correct.
Root Cause
There was a top-level blog/ directory used for article source files.
At the same time, page routing used src/pages/blog/index.astro.
So the real directory blog/ conflicted with URL segment /blog.
Under bun dev, this collision caused the 404.
Fix
- Move article source files from
blog/tocontent/blog/ - Update loader base in
src/content.config.tsto./content/blog
After this, /blog/ rendered correctly in bun dev.
Reusable Check Order
If the same issue appears again:
- Confirm
bun run buildgenerates/blog/index.html - Confirm nav link in
dist/index.htmlpoints to/blog/ - Confirm
prefixDefaultLocalebehavior and expected/ja/blog/ - Check for any project-root directory with the same name as the URL segment
Key Takeaways
- Avoid using the same name for Astro URL segments and project-root directories
- If build works but dev fails, compare delivery path behavior first
- For 404 debugging, separate checks into link values, route generation, and actual files
hsb.horse