Vite has quickly become one of the leading build tools for modern frontend development, known for its lightning-fast bundling, excellent developer experience, and effortless integration with popular frameworks like React, Vue, and Svelte. But despite its ease of use, many developers encounter a common yet confusing issue: running the Vite server only to get an HTML file displayed instead of their functional app.
You’re not alone—this scenario happens more often than you might think. Typically, when you run your Vite app, you expect to see your dynamic JavaScript application rendered smoothly in the browser. However, receiving a static HTML file instead can be perplexing and frustrating, especially for developers who are new to Vite or modern frontend tooling.
Why does this happen? Usually, it’s due to improper configurations, file structure errors, incorrect use of Vite commands, or misunderstanding how the Vite server actually serves static assets.
In this comprehensive guide, we’ll break down why you’re encountering the issue, outline common reasons behind it, and provide clear, step-by-step instructions on how you can quickly resolve the HTML display issue in your Vite app.
Understanding the Issue (HTML file displayed instead of the App)
When starting your Vite development server with commands like npm run dev
, you ideally anticipate your modern JavaScript application: your page components, styles, and functionalities. Instead, developers occasionally face a situation where the browser only displays raw HTML content—no interactive components or styles, just plain static HTML.
What does the HTML file signify?
The index.html
file acts as the key entry point for your Vite app. While traditional sites treated HTML files as static markup that browsers directly served, modern single-page applications (SPAs) like those built with Vite use the initial index.html
file only to bootstrap JavaScript code. Thus, your HTML file alone typically lacks functionality unless JavaScript properly loads and kicks in.
If your page remains purely HTML without interaction, it usually indicates:
- Incorrect file paths or missing JavaScript imports.
- Improperly configured dev server.
- Incorrect commands used (building vs developing).
Vite intentionally serves index.html
because it’s the fundamental template. The problem arises when JavaScript doesn’t properly load or configure to render your entire application.
Common Reasons for the HTML Display Issue and How to Identify Them
Reason 1: Incorrect Entry Point or File Structure
The most common cause of this issue lies in improper file organization or wrong file paths. Vite typically expects:
- Your root should contain
index.html
. - JavaScript codes and major assets inside a
src
directory. - A JavaScript main entry file (
main.js
,main.jsx
,main.tsx
, or similar).
Your structure should look like this:
vite-app/
├── node_modules/
├── public/
├── src/
│ ├── App.jsx
│ └── main.jsx
├── index.html
├── package.json
└── vite.config.js
If your structure differs drastically from this recommended format, the app may fail and only show raw HTML.
Reason 2: Vite Server Misconfigured or Not Running Properly
Vite projects can be customized via vite.config.js
or vite.config.ts
. Misconfigurations here—such as incorrect paths, server port designations, or build targets—regularly cause issues such as HTML-only output.
Reason 3: Improperly Linked Scripts or Bundles in index.html
Incorrect script references are a very frequent reason why your app doesn’t load JavaScript bundles:
- Broken
src
paths. - Trying to manually insert bundle URLs wrongly.
A correct vital import typically looks like:
<script type="module" src="/src/main.jsx"></script>
Any deviation from the proper referencing format will cause the application to fail in displaying dynamically rendered content.
Reason 4: Using Incorrect Vite Commands or Build Procedures
Vite offers several commands influenced by your package.json
scripts, primary ones that are:
vite
ornpm run dev
– starts the dev server.vite build
ornpm run build
– generates static production-ready assets.vite preview
ornpm run preview
– locally tests production build assets.
If you mistakenly use “build” instead of “dev,” you’ll serve static files that behave differently than your expectation.
Step-by-Step Solutions to Fix the HTML Issue with Vite Apps
Solution 1: Verify Your Project Setup and Folder Structure
Crosscheck your project structure to match Vite’s recommended folder setup:
- Ensure
index.html
is exactly inside your root directory. - Confirm your JavaScript entry point is correctly located and properly referenced inside
index.html
.
For instance, typically you will have:
<script type="module" src="/src/main.jsx"></script>
Solution 2: Check Your vite.config.js
or vite.config.ts
Any unexpected line or typo here can cause rendering issues. An example minimal correct configuration is:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()]
});
Checklist to debug Vite Configuration:
- Have you installed required plugins?
- Is
root
property set correctly (usually defaults are enough)? - Ensure no path mismatch.
Solution 3: Ensure Scripts in HTML are Properly Linked
Always confirm your script tag inside index.html
points to the correct file:
- Use “type=module”.
- Avoid adding extra prefixes or incorrect paths.
Solution 4: Run the Appropriate Vite Command
Check your scripts in package.json
:
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
Remember:
- Use
npm run dev
during the app-building process in development. - Use
npm run build
followed bynpm run preview
for final testing your production builds.
Also read: How to View the HTML Source in Google Chrome
Practical Example / Walkthrough
Let’s briefly troubleshoot together:
- Step 1: Create a new simple Vite React app:
npm create vite@latest my-react-app -- --template react
- Step 2: Navigate and run:
cd my-react-app npm install npm run dev
- Step 3: If your app still outputs HTML-only, check file paths inside
index.html
again carefully. - Step 4: Ensure the Vite config matches the default correct config previously described.
Doing this carefully should most often instantly solve HTML-displaying issues and render your React/Vue/Svelte app correctly.
Advanced Troubleshooting and Tips
- Open Browser Developer Tools (
F12
) and check for errors in Console and Network tabs. - Refresh cache: Use “Disable Cache” under Network Tools panel.
- Run Vite with verbose logs to identify underlying issues.
Frequently Asked Questions (FAQs)
Q1: Why does Vite always serve an index.html
?
Vite primarily supports single-page applications (SPAs). The index.html
acts as the entry point that loads JavaScript, rendering entire applications dynamically.
Q2: My Vite app runs locally but displays HTML after deployment. Why?
This happens due to routing setup differences on production hosts. Try properly configuring your hosting service (such as Netlify or GitHub Pages) to handle SPA routing.
Q3: How can I validate if my Vite server correctly serves JavaScript assets?
Open browser developer tools and visit the Network tab. You should clearly see JavaScript files importing successfully (status code 200).
Q4: Should my index.html
always be in the root directory?
Typically, yes. Although Vite can support different structures, placing it at root is recommended best practice to avoid path confusion.
Q5: What’s the difference between vite dev
, vite build
, vite preview
?
vite dev
: Runs the dev-server with real-time HMR and debugging.vite build
: Prepares assets for production deployment.vite preview
: Previews built production assets.
Conclusion
Encountering only HTML displayed instead of your functional Vite app is a common scenario. Usually, it relates to file path configuration, script linking, or invalid commands. By following this guide, you can rapidly pinpoint and troubleshoot this exact issue.
Understanding these fundamentals makes you a skilled debugger and streamlines your development process. If you’ve fixed your issue using this guide or need more insights, feel free to comment below and share your experiences.
Also read: How To Save Inspect Element Changes Permanent | Html Tutorial
Stay Updated & Subscribe!
Love this article? Subscribe to our newsletter for more frontend tips and guides like this. Stay current with Vite, web development best practices, and get exclusive resources sent directly to your inbox!