Getting started with Vite and debugging builds: why do assets disappear after development?

December 25, 2024

On December 25, 2024, I cloned PuppyAgent-Engine locally and started preparing the development environment. Five days later I asked Cursor to help build a flowchart editor in a React Flow experiment. Its replies already referred to vite-project/src/App.jsx. The surviving package.json has a command each for development, building, and previewing. Packaging a React page in Electron gave me a more concrete question: why can the dev server display a page whose built version cannot find its JavaScript and CSS?1

Start with a page that runs

For a fresh React experiment, use the official scaffolding tool. The example below uses the current template; see the getting started guide for Node.js requirements. For an existing project, read its own package.json. For example, my React Flow experiment specified Vite ^6.0.5.21

npm create vite@latest vite-demo -- --template react
cd vite-demo
npm install
npm run dev

Open the address printed in the terminal, edit some text in src/App.jsx, and save to see the change. Then stop the development server, run the two commands below, and check the preview address. This is a good way to isolate failures that occur only after a build.3

npm run build
npm run preview
Observation pointWhat Vite doesWhat to inspect
Page opened by devThe development server transforms requested source modules and can hot-replace updates.Look at the module requests in Network and the first application error in Console.
Directory generated by buildA typical frontend starts at the root index.html, follows imports, and processes JS, CSS, and assets into deployable files.Open the output index.html and compare each src and href with the files on disk.
Page opened by previewServes the newly built files locally over HTTP.Verify the build, then serve the same directory in production. In Electron also try the actual page-loading mechanism.

On March 18, while debugging an MCP client, I asked about converting TSX to JavaScript without bundling or minifying it. First decide what to deliver. For a whole web page, build with Vite from the HTML entry. Disabling minification still produces bundled modules. To inspect output file by file, set outDir and enable emit in a separate TypeScript configuration, then run tsc -p <config-file>. With jsx: "preserve" you get .jsx files that retain JSX. A React project can use jsx: "react-jsx" for .js output that needs no further JSX compilation.4

While debugging IndexedDB in Meowssenger, I saw [vite] connected even though the page did not show the expected result. The message only confirmed that the development client had connected to hot updates. I still needed to check whether IndexedDB initialization finished, what the read callback received, and whether the component updated the UI with that value.5

Why does the HTML open while JS, CSS, and model files return 404?

On March 2 I asked how to make Electron’s built asset references start with ./ and, in the same conversation, how to change the output directory. You can test these independently. base changes the resource addresses written into the HTML; build.outDir determines where the HTML and its assets land on disk. Rebuild after changing either.67

Deployment or symptomSettingVerification
The site lives under /tools/ but requests go to /assets/… at the root.Build with base: '/tools/' and mount the output directory there.Request the exact /tools/assets/… URL referenced by the built HTML.
Electron opens HTML with loadFile, but asset URLs start with /assets/.Use relative base: './'.Inspect the failed file: URL in Electron’s Network panel and check that assets are resolved next to the HTML.
The desktop app looks in desktop/dist while Vite still writes to web/dist.In the project rooted at web, set build.outDir: '../desktop/dist'.Rebuild and check the location and contents of the index.html actually being loaded.

I also tried changing React’s homepage and watching Electron navigation events. Page navigation, asset requests issued by HTML, and disk locations each have their own entry point. For why homepage did not solve that case, see debugging a locally loaded React page in Electron.

In ChatUI-onnx on May 19, it was a different file that went missing. The model loader requested /assets/Qwen3-0.6B-ONNX/tokenizer.json from the dev server and reported a missing local file, followed by an invalid model ID. I asked “why src/asset is not exposed”. For cascading errors like these, request the JSON on its own and inspect the status and body. If it returns the app’s HTML, a 200 status still will not give the loader a vocabulary.8

An image in source can be imported with import logoUrl from './assets/logo.svg', then the returned URL passed to an img element. The build tool can rename, hash, or inline the file and the caller gets its processed URL. Model loaders often take a directory and look up the tokenizer, configuration, and weights by agreed names. Put the complete set in public/models/Qwen3-0.6B-ONNX/. At the site root, /models/Qwen3-0.6B-ONNX/tokenizer.json should then return the file directly. The output path is dist/models/…; neither the URL nor the build output contains the public segment.9

When mounted at /tools/, a runtime fetch('/models/…') still goes to the domain root. Construct the model directory with import.meta.env.BASE_URL + 'models/Qwen3-0.6B-ONNX/' and check the final URL in Network. A source alias helps resolve imports, but cannot create files at HTTP addresses expected by the loader.79

Why does Vite report Buffer or entry-point errors when the dependency is installed?

My Lite MCP SDK once exported its browser client and Node server from one entry point. On April 2 the page only wanted an MCP service connection, yet safer-buffer threw an error while reading Buffer.prototype. Following the stack back, the server’s request-body reader raw-body imported iconv-lite, which imported safer-buffer. Vite had reported “Module "buffer" has been externalized for browser compatibility.” The module named there was more informative than the final undefined error.10

Vite 6 has two processing paths here. In development it scans for package imports such as import … from 'some-package' and prebundles dependencies with esbuild. Browsers can load them as ESM without making a request for every small module in a package. Production builds use Rollup to generate the final output from the application entry. If a locally linked package has changed but the browser still sees old code, run npm run dev -- --force to prebundle again. Rebuilding the cache cannot give the browser a Node-only API.11

Preparing a browser entry for the SDK exposed another issue. On April 3, vite:dep-pre-bundle reported a missing ./dist/browser.mjs specifier. First check the consumer’s package name or subpath, then whether the package’s exports exposes that entry, then whether the installed package actually contains the file. Lite MCP SDK had separate commits that day for the lower- and upper-level browser entries. See Buffer errors when importing an SDK in a browser and package subpaths and conditional exports.10

On April 24, the asset management project showed a similar warning when the login page called crypto.createHash. The fix depends on where the operation belongs. Browser-side hashing can use Web Crypto; authentication logic that depends on Node belongs on the server. Identify the line importing the Node module before deciding whether to change the caller or split the package. Vite troubleshooting guide5

How can I see whether an installed plugin processed a particular file?

While debugging a form on March 2, I saw a button whose hover style did not work as expected. PromptPulse later used the React and Tailwind Vite plugins together. I also remember investigating plugin order. For this button we can narrow the problem to one rule before guessing which plugin failed.12

  1. Inspect the input. App.jsx imported App.css, the CSS contained @import "tailwindcss", and the JSX button used hover:border-pink-400. A missing stylesheet entry, a class the scanner missed, or a theme branch that did not use the class could all produce the same symptom.
  2. Inspect the output. Search the generated CSS for the escaped selector, for example with rg -F 'hover\:border-pink-400' ../desktop/dist/assets -g '*.css'. If the rule exists, force :hover in the browser and inspect the actual class, matching media queries, and winning border rule. Rebuilding the March 6 source did produce the selector. I still cannot establish what caused the earlier hover problem.13
  3. Check order when an expected transform is missing. Use npm run dev -- --debug or npm run build -- --debug to inspect resolved plugins. Check whether apply restricts a plugin to serve or build, and whether it handles the target file and hook. For two custom transform plugins, log the target module’s id and relevant input snippet in each hook. See which receives the original and which gets the previous output. Verify output-only hooks with build.14

The configuration array is only the starting point. Vite processes aliases, user plugins with enforce: 'pre', core plugins, ordinary user plugins, build plugins, user plugins with enforce: 'post', and final build plugins. Within a group, check declaration order and any order specified by the hook itself. If one plugin consumes another’s output, check that they are in the same group. Swapping their array positions across groups might not change execution order at all.14

How do I deliver one frontend build to Electron or to a backend?

On March 4 I investigated a series of entry errors in electron-vite. Cursor first suggested specifying a main-process entry. I tried it and replied “not solving the problem”. The discussion then moved to a renderer missing ./dist_copy/index.html and an output filename containing ../../dist3/index.html. In retrospect, one question was which file starts the build and the other was what filenames are permitted inside the output directory. Putting the output path back into an entry field can lead in circles. That conversation did not record a successful complete configuration.15

Around then I also asked how to make node-llama-cpp external. In a desktop main process with Node, an external dependency can load at runtime. The distribution tool must still place its package, native bindings, and model where the app can find them. I consulted electron-vite’s Build, Distribution, and Assets docs and Forge Vite’s native module notes. See the PromptPulse development notes for the separate entries and runtimes of the main process, preload, and renderer.15

The configuration actually committed to PromptPulse was short. On March 4 web/vite.config.js already had a relative base and the Tailwind and React plugins. On March 6 I asked about changing ./dist to ../desktop/dist. That day’s commit only added build.outDir to this configuration. The excerpt below omits the imports.613

export default defineConfig({
  base: './',
  build: { outDir: '../desktop/dist' },
  plugins: [tailwindcss(), react()],
})

After building from web, Electron can load index.html from its own dist directory. Rebuilding the historical source did produce desktop/dist, and the script and stylesheet in its HTML pointed to ./assets/index-….js and ./assets/index-….css. The build also warned that the target was outside the frontend root and would not be emptied by default. Reserve that directory for build output.13

In June my SQL management tool also shipped dist, but the backend needed to serve the Solid frontend directly. Check the files with preview, then through the real backend, verifying the static directory and mount prefix. If the homepage opens but refreshing a nested route returns 404, add an index.html fallback for frontend page routes while preserving errors for missing assets and API requests.316

Why is the page still wrong after changing target or an environment variable?

Check JavaScript, runtime APIs, and CSS separately for older browsers. The SQL tool’s June 22 commit mentions Chrome 80 and the frontend uses build.target: 'es2015'. The next day I explicitly asked for Chrome 70 compatibility and separately asked about Tailwind. Vite can transform some JS syntax, but API availability and support for generated CSS properties need independent checks. Open the same build in the target browser, look for syntax or API errors, then inspect computed styles on a component that actually fails. The records confirm the target and config change; I do not have a final result from a real Chrome 70 installation.716

Client configuration enters the code at build time. The asset management frontend used VITE_BACKEND_URL; the SQL tool used VITE_LANGUAGE. Restart the dev server after changing the mode’s .env file. Changing server environment variables after deployment requires a new frontend build before the generated JS reflects the change. If a request goes to the frontend on port 5173, inspect the full URL in Network. A relative /api/… goes to the page’s origin, so it needs a same-origin backend mount, development proxy, or explicit API address. In a July interview-agent conversation the assistant suggested VITE_DEEPSEEK_API_KEY. Anyone can read a value shipped to the browser in code or requests; a server-side key belongs on the backend that calls the model.175

References

Footnotes

  1. CaiBorui. (2024, December 25–30; 2025, January 2). PuppyAgent-Engine 与 React Flow 实验 [本地 Git reflog、Cursor 会话与 Git 提交]。文章日期取 Engine 克隆日 12 月 25 日。12 月 30 日会话 Creating a Flow Chart App with React Flow 中,19:37 的回复出现 vite-project/src/App.jsx;实验仓库提交 91bafaf 保存了脚本与版本范围。本文在 2026 年 11 月 18 日整理,交流时间按北京时间,缺少独立时间戳的用户消息按相邻回复定位。官方指南核对于整理日,历史实现按项目版本说明。 ↩ ↩2

  2. Vite contributors. (n.d.). Getting started. Vite. Scaffolding your first Vite project. ↩

  3. Vite contributors. (n.d.). Deploying a static site. Vite. 本地预览和部署步骤. ↩ ↩2

  4. CaiBorui. (2025, March 18). MCP Client Connection Error Troubleshooting [与 Cursor 的开发对话,关于只输出 JS 和转换 App.tsx 的两次追问]。配置语义见 Microsoft. (n.d.). JSX. TypeScript Handbook. Basic usage 中的输出模式表。 ↩

  5. CaiBorui. (2025, April–July). Implementing Action Logs API Endpoints(API 端口)、SQLite Middleware Modification for User Validation(4 月 24 日登录报错)、Implementing Get All Users Function(后端地址)、Use indexedDB instead of local storage(6 月 4 日控制台日志)、Use double curly braces for replacements(语言配置)、Add text input and restructure LLM logic(助手提出的前端环境变量)[与 Cursor 的开发对话,作者留存]。 ↩ ↩2 ↩3

  6. CaiBorui. (2025, March 2–6). Setting Vite Build to Use Relative Paths;Change Vite Build Directory Configuration [与 Cursor 的开发对话]。前一会话第 1、3 条消息分别问相对 URL 和输出目录;后一会话首条消息指定了目标目录。 ↩ ↩2

  7. Vite contributors. (n.d.). Building for production. Vite. 构建入口与公共路径;Vite 6 的浏览器兼容性. ↩ ↩2 ↩3

  8. CaiBorui. (2025, May 19). ChatGPT UI Implementation with Tailwind CSS [与 Cursor 的开发对话,第 7 条用户提问和第 9 条消息中的 tokenizer 请求错误]。正文的模型目录是按 Vite 资源规则改写的示例。 ↩

  9. Vite contributors. (n.d.). Static asset handling. Vite. 导入资源 URL;public 目录. ↩ ↩2

  10. CaiBorui. (2025, April 2–3). JavaScript to Python Code Translation [与 Cursor 的开发对话,第 11 条消息中的控制台警告,及次日的包入口排查]。实现见 CaiBorui [S2thend]. (2025, April 3). Lite MCP SDK browser entry changes. GitHub. 浏览器入口提交。 ↩ ↩2

  11. Vite contributors. (n.d.). Dependency pre-bundling. Vite. 依赖发现与缓存;Vite 6 的预构建过程. ↩

  12. CaiBorui. (2025, March 2–6). Tailwind CSS Input Form Design;Adding a Chat Bot UI with Tailwind CSS [与 Cursor 的开发对话]。输入表单会话涉及 hover 与 focus 状态。另据作者 2026 年 11 月 18 日关于插件顺序排查的回忆。代码见 3 月 6 日的按钮样式。 ↩

  13. CaiBorui [S2thend]. (2025, March 4–6). PromptPulse [Git 提交]. GitHub. 3 月 4 日的前端配置;3 月 6 日更改前端输出目录。整理时在临时目录用后一次提交的源码和本地已有依赖(Vite 6.2.0)重新构建,核对了 HTML、资源 URL 和生成的 CSS。 ↩ ↩2 ↩3

  14. Vite contributors. (n.d.). Using plugins;Plugin API. Vite. 启用插件与顺序;Plugin ordering. ↩ ↩2

  15. CaiBorui. (2025, March 4–6). Electron Vite Configuration Issue;Bundling Electron Apps: Excluding node-llama-cpp [与 Cursor 的开发对话]。引文出自前一会话第 3 条消息,后续回复涉及 main 和 renderer 入口。参考 electron-vite contributors. (n.d.). Building for production、Distribution、Asset handling;Electron Forge contributors. (n.d.). Vite plugin, Native Node modules. ↩ ↩2

  16. CaiBorui [S2thend]. (2025, June 22). Add support for compatibility with Chrome 80 [Git 提交]. GitHub. 该版本的 webui/vite.config.js。另见 CaiBorui. (2025, June 23). Add endpoint for frontend dist folder;Send sqlsMap with server sent events [与 Cursor 的开发对话]。后者 13:17 的用户提问明确指定 Chrome 70,13:53 追问 Tailwind。 ↩ ↩2

  17. Vite contributors. (n.d.). Env variables and modes. Vite. 环境变量与客户端可见性. ↩

© 2024 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2024-12-25). Getting started with Vite and debugging builds: why do assets disappear after development?. https://caiborui.com/blog/2024-12-25-zh-vite-build-assets-and-plugins-entrans

@misc{borui2024-f73a0438,
  author = {borui},
  title = {{Getting started with Vite and debugging builds: why do assets disappear after development?}},
  year = {2024},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2024-12-25-zh-vite-build-assets-and-plugins-entrans}
}