Skip to content

"<script>" in string literal in <script> element in HTML fails to parse #21150

@jamesnw

Description

@jamesnw

Describe the bug

In my index.html file, I have a script element in the <head>. Inside of that, I have a string literal that includes "</script>". This throws the following error:

[vite] (client) Pre-transform error: Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .js file format, or if it's an asset, add "**/*.js" to `assetsInclude` in your configuration.
  Plugin: vite:import-analysis

Reproduction

https://stackblitz.com/edit/vitejs-vite-u2lf5z82?file=index.html

Steps to reproduce

Open the Stackblitz.

The only change from the boilerplate is the addition of this in the index.html file-

<script type="module">
    // This line breaks
    const string = `</script>`;
    </script>

System Info

System:
    OS: macOS 26.1
    CPU: (11) arm64 Apple M3 Pro
    Memory: 95.52 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.19.5 - /Users/jamessw/.nvm/versions/node/v20.19.5/bin/node
    Yarn: 1.22.22 - /Users/jamessw/.yarn/bin/yarn
    npm: 10.8.2 - /Users/jamessw/.nvm/versions/node/v20.19.5/bin/npm
    Deno: 1.44.1 - /Users/jamessw/.deno/bin/deno
    Watchman: 2025.07.14.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 142.0.7444.176
    Chrome Canary: 144.0.7543.0
    Edge: 142.0.3595.94
    Firefox Nightly: 147.0a1
    Safari: 26.1
    Safari Technology Preview: 26.0
  npmPackages:
    vite: ^7.1.12 => 7.1.12

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions