vite icon indicating copy to clipboard operation
vite copied to clipboard

Error parsing html while build (Cannot use replaced character as slice start anchor)

Open wclr opened this issue 1 year ago • 2 comments
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

wclr avatar Dec 12 '23 13:12 wclr

i noticed this only happens when using <script type="module">.

<script>, <script defer>, etc work fine

mayank99 avatar Dec 20 '23 22:12 mayank99