Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
7 tasks done
wclr opened this issue Dec 12, 2023 · 2 comments · Fixed by #15435
Closed
7 tasks done

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

wclr opened this issue Dec 12, 2023 · 2 comments · Fixed by #15435
Labels
feat: html p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@wclr
Copy link

wclr commented Dec 12, 2023

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

Copy link

stackblitz bot commented Dec 12, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@mayank99
Copy link
Contributor

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

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

@bluwy bluwy added feat: html p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Dec 27, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: html p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants