Closed
Description
Describe the bug
Some tags are optional in HTML. For example, <head>
, <body>
and <html>
. The closing tag of <html>
can be omitted. A body is started implicitly when the first non-<head>
-element is created.
This seems to cause issues with vite's parser.
Reproduction
This HTML template:
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Hi</title>
<div>Hi</div>
<script type="module" src="/src/main.ts"></script>
Causes a parsing error, probably due to the missing </html>
:
[vite:build-html] Unable to parse {"file":"/<path/>index.html","line":2,"column":1}
1 | <!DOCTYPE html>
| ^
2 | <html lang="en">
3 | <meta charset="utf-8">
Adding </html>
fixes this:
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Hi</title>
<div>Hi</div>
<script type="module" src="/src/main.ts"></script>
</html>
But then, the script and styles are positioned before <!doctype html>
:
<script type="module" crossorigin src="/assets/index.ad4f7fa4.js"></script>
<link rel="stylesheet" href="/assets/index.06d14ce2.css">
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Hi</title>
<div>Hi</div>
</html>
Adding a <head>
and <body>
also fixes this.
System Info
System:
OS: Linux 4.4 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (24) x64 AMD Ryzen 9 3900X 12-Core Processor
Memory: 21.49 GB / 31.95 GB
Container: Yes
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.13.0 - /usr/bin/node
Yarn: 1.22.11 - ~/.npm-bin/bin/yarn
npm: 7.24.1 - ~/.npm-bin/bin/npm
npmPackages:
vite: ^2.6.4 => 2.6.14
Used Package Manager
npm
Logs
vite v2.6.14 building for production...
✓ 0 modules transformed.
[vite:build-html] Unable to parse {"file":"<path>/vite-project/index.html","line":2,"column":1}
1 | <!DOCTYPE html>
| ^
2 | <html lang="en">
3 | <meta charset="utf-8">
file: <path>/vite-project/index.html
error during build:
Error: Unable to parse {"file":"<path>/vite-project/index.html","line":2,"column":1}
1 | <!DOCTYPE html>
| ^
2 | <html lang="en">
3 | <meta charset="utf-8">
at traverseHtml (<path>/vite-project/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:21240:15)
at async Object.transform (<path>/vite-project/node_modules/vite/dist/node/chunks/dep-e0fe87f8.js:21305:17)
at async ModuleLoader.addModuleSource (<path>/vite-project/node_modules/rollup/dist/shared/rollup.js:22148:30)
at async ModuleLoader.fetchModule (<path>/vite-project/node_modules/rollup/dist/shared/rollup.js:22201:9)
at async Promise.all (index 0)
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Type
Projects
Status
Discussing