Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Vite prints "Unable to parse HTML; parse5 error code eof-in-element-that-can-contain-only-text"

ErrorUnable to parse HTML; parse5 error code eof-in-element-that-can-contain-only-text

Short answer

Vite reads your HTML with the parse5 parser. This code means the file ended while a script, style, title or textarea element was still open. The warning names the file, line and column. Close the element with a real end tag: a self-closing script tag does not count, because the parser ignores the slash.

  • Applies to Vite 7, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Start the dev server (or run a build) and read the warning. After the error code it prints the file, the line and the column, then a code frame with the tag that was left open. Vite keeps only the first hit for each error code, so fix it, run again and look for the next one.

    npm run dev
    npx vite build
  2. 2Match what you see, then jump to its fix

    1. 1The code frame shows a tag such as <script type="module" src="/src/main.jsx" />A script, style, title or textarea tag is written as self-closingFix
    2. 2The code frame points at a start tag whose matching end tag never appears below itAn end tag is missing or misspelledFix
    3. 3The file named after "at" in the warning is not your main index.htmlAnother HTML page of the project is the broken oneFix

What does the error look like?

  • Unable to parse HTML; parse5 error code eof-in-element-that-can-contain-only-text
  • at /app/index.html:14:1

Cause 1 of 3

A script, style, title or textarea tag is written as self-closing

1Check

On an element that is not void and not SVG or MathML, a trailing slash is ignored by the HTML parser, so the tag stays open and everything after it is read as the text of that element, up to the next matching end tag or the end of the file. Vite stays quiet about the slash itself, which is why the end-of-file code is the first thing you see.

grep -rnE "<(script|style|title|textarea)\b[^>]*/>" --include="*.html" --exclude-dir=node_modules --exclude-dir=dist .

2Fix

Write the element with an explicit end tag. This is the most common form after copying a JSX or XML snippet into index.html.

<!-- before -->
<script type="module" src="/src/main.jsx" />

<!-- after -->
<script type="module" src="/src/main.jsx"></script>

3Verify

Restart the dev server. The warning must be gone and the page must load the entry script.

npm run dev

Confirmed by html.spec.whatwg.org

Did this fix it?

Cause 2 of 3

An end tag is missing or misspelled

1Check

Script and style are raw text elements, and textarea and title are escapable raw text elements. Each needs a start tag and an end tag. List every one of them in the file and pair them by eye; a typo such as a missing slash in the end tag counts as no end tag.

grep -n -i -E "</?(script|style|title|textarea)" index.html

2Fix

Add or correct the end tag at the right place. If the file looks cut off, for example after a failed save or a merge, restore the missing part rather than patching around it.

<head>
  <title>My app</title>
  <style>
    body { margin: 0; }
  </style>
</head>

3Verify

Restart the dev server and open the page. No parse warning should appear in the terminal.

npm run dev

Confirmed by html.spec.whatwg.org

Did this fix it?

Cause 3 of 3

Another HTML page of the project is the broken one

1Check

Vite parses every .html file that is an entry of the build, so an app with several pages has several files that can carry the problem. The warning names the file, line and column; open the one it names instead of index.html.

find . -name "*.html" -not -path "./node_modules/*" -not -path "./dist/*"

2Fix

Repair that file as in the first two causes. If it is a leftover that is not a real page, delete it or take it out of the build entries, so that Vite no longer reads it.

<!-- about.html -->
<body>
  <div id="app"></div>
  <script type="module" src="/src/about.js"></script>
</body>

3Verify

Run the build again; every HTML entry is parsed and no warning should be printed.

npx vite build

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Always write script, style, title and textarea with a full end tag, in every HTML file the build reads.
  • Keep scratch or exported HTML pages out of the project folders that Vite uses as page entries.
  • Read the first lines of the Vite output after each change to an HTML file.
  • Let the editor close tags for you instead of typing them, which stops typos in end tags.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.