vite
vite copied to clipboard
Error parsing html while build (Cannot use replaced character as slice start anchor)
trafficstars
Describe the bug
For example index.html like this:
<html><head><style>div {}
</style></head><body><script type="module" src="./vite.entry.js"></script></body></html>
Will not build with the error:
[vite:build-html] Cannot use replaced character 26 as slice start anchor.
Reproduction
https://stackblitz.com/edit/vitejs-vite-zjnwkg?file=index.html&terminal=dev
Steps to reproduce
https://stackblitz.com/edit/vitejs-vite-zjnwkg?terminal=dev
vite v5.0.8 building for production...
✓ 0 modules transformed.
[vite:build-html] Cannot use replaced character 26 as slice start anchor.
file: /home/projects/vitejs-vite-zjnwkg/index.html
error during build:
Error: Cannot use replaced character 26 as slice start anchor.
at MagicString.slice (/home/projects/vitejs-vite-zjnwkg/node_modules/vite/dist/node/chunks/dep-uAHLeuC6.js:7299:10)
at nodeStartWithLeadingWhitespace (/home/projects/vitejs-vite-zjnwkg/node_modules/vite/dist/node/chunks/dep-uAHLeuC6.js:38582:36)
at eval (/home/projects/vitejs-vite-zjnwkg/node_modules/vite/dist/node/chunks/dep-uAHLeuC6.js:38772:34)
at traverseNodes (/home/projects/vitejs-vite-zjnwkg/node_modules/vite/dist/node/chunks/dep-uAHLeuC6.js:38460:5)
at eval (/home/projects/vitejs-vite-zjnwkg/node_modules/vite/dist/node/chunks/dep-uAHLeuC6.js:38464:48)
at traverseNodes (/home/projects/vitejs-vite-zjnwkg/node_modules/vite/dist/node/chunks/dep-uAHLeuC6.js:38464:25)
at eval (/home/projects/vitejs-vite-zjnwkg/node_modules/vite/dist/node/chunks/dep-uAHLeuC6.js:38464:48)
at traverseNodes (/home/projects/vitejs-vite-zjnwkg/node_modules/vite/dist/node/chunks/dep-uAHLeuC6.js:38464:2
System Info
vite 5.0.8
Used Package Manager
npm
Logs
No response
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] 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 vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
i noticed this only happens when using <script type="module">.
<script>, <script defer>, etc work fine