最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Vite dev server won't serve a new JSON files from public - Stack Overflow

programmeradmin3浏览0评论

I'm working on a React project using Vite. My JSON files are placed in public/data/2025. Most of them, such as muenster.json, load just fine via http://localhost:5173/data/2025/muenster.json. However, every newly added file, e.g. cologne.json, keeps failing. Vite just serves index.html for those files.

I have verified that:

  • The file paths are correct (public/data/2025/cologne.json).

  • The JSON file is valid JSON (checked with JSON validators).

  • The file permissions are the same as muenster.json.

  • I've tried removing any possible BOM (Byte Order Mark) or hidden characters using hexdump and xattr on macOS.

  • I restarted the dev server multiple times (npm run dev).

  • I tested a minimal file ({"test":true}) in the same folder, and that also doesn't load.

  • My vite.config.js is very minimal:

    import { defineConfig } from 'vite' import react from '@vitejs/plugin-react'
    
    export default defineConfig({ plugins: [react()], server: { fs: { strict: false } } })
    

Other JSON files from that folder can be fetched and parsed without issues. Why would one (or more) JSON file(s) in public/data/ not be served properly, while all the others are? Is there something else I need to configure in Vite to ensure every file in the public folder is served without issues?

发布评论

评论列表(0)

  1. 暂无评论