diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts
index b8cd3713edfeea..4c46d988890462 100644
--- a/packages/vite/src/node/plugins/html.ts
+++ b/packages/vite/src/node/plugins/html.ts
@@ -7,6 +7,7 @@ import type {
SourceMapInput
} from 'rollup'
import MagicString from 'magic-string'
+import colors from 'picocolors'
import type {
AttributeNode,
CompilerError,
@@ -54,6 +55,10 @@ const inlineImportRE =
/(?]*type\s*=\s*["']?importmap["']?[^>]*>.*?<\/script>/is
+const moduleScriptRE = /[ \t]*