Skip to content

Conversation

@SE7EN2028
Copy link

What is this PR solving?

-This PR improves the error message produced by the vite:import-analysis plugin when an inline <script> in an HTML file is prematurely terminated because the literal sequence </script> appears inside a JavaScript string or template literal.
The updated message clearly explains why the script was truncated and how to fix it (escape as </script> or move the code to an external file), making the error much easier to understand for users.

-Fixes #21150.

-Leaving the existing generic error message as-is.
This was rejected because it provides no guidance for a very common and confusing HTML parsing pitfall.

Always showing the </script> hint.
This would introduce noise for non-HTML importers such as .js, .ts, or .vue.

The chosen approach — showing the note only for .html/.htm importers — keeps the message relevant and minimal.

-This is a messaging-only change; no logic or behavior is modified.

The only added check is isHtmlImporter, which ensures the hint appears only for HTML files.

Reviewers may want to confirm that this condition aligns with Vite's existing conventions for detecting HTML importers.

-Previously Vite produced an unclear message:
([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...)

This was especially confusing when triggered by the following valid HTML:

<!doctype html>

<script type="module"> // problematic line: HTML parser will see </script> unless escaped const s = `</script>`; </script>

@SE7EN2028
Copy link
Author

Hi! I noticed the related issue was closed.

Just checking whether this error-message improvement is still something you'd consider merging. This PR doesn't change any behavior — it only improves the clarity of the error shown when an inline <script> is terminated early due to the literal </script> sequence in HTML.

If this isn’t something you want to include right now, feel free to close the PR. Just wanted to confirm before doing so.

Thanks for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant