Describe the bug
In production builds Vite moves scripts tags, breaking order of execution with <script vite-ignore type="module">.
Reproduction
https://stackblitz.com/edit/vitejs-vite-i5gjryer?file=index.html
Steps to reproduce
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>script execution order</title>
</head>
<body>
<script vite-ignore type="module">
window.leet = 1337;
</script>
<script type="module">
document.body.append(`Should be leet: ${window.leet}`);
</script>
</body>
</html>
vite dev -> “Should be leet: 1337”
vite build && vite preview -> “Should be leet: undefined”
System Info
System:
OS: macOS 26.2
CPU: (14) arm64 Apple M4 Pro
Memory: 5.69 GB / 48.00 GB
Shell: 4.3.3 - /opt/homebrew/bin/fish
Binaries:
Node: 24.12.0 - /Users/simon.lydell/.local/share/nvm/v24.12.0/bin/node
npm: 11.6.2 - /Users/simon.lydell/.local/share/nvm/v24.12.0/bin/npm
Browsers:
Chrome: 144.0.7559.132
Firefox Developer Edition: 148.0
Safari: 26.2
npmPackages:
vite: ^7.2.4 => 7.3.1
Used Package Manager
npm
Logs
No response
Validations
Describe the bug
In production builds Vite moves scripts tags, breaking order of execution with
<script vite-ignore type="module">.Reproduction
https://stackblitz.com/edit/vitejs-vite-i5gjryer?file=index.html
Steps to reproduce
vite dev-> “Should be leet: 1337”vite build && vite preview-> “Should be leet: undefined”System Info
System: OS: macOS 26.2 CPU: (14) arm64 Apple M4 Pro Memory: 5.69 GB / 48.00 GB Shell: 4.3.3 - /opt/homebrew/bin/fish Binaries: Node: 24.12.0 - /Users/simon.lydell/.local/share/nvm/v24.12.0/bin/node npm: 11.6.2 - /Users/simon.lydell/.local/share/nvm/v24.12.0/bin/npm Browsers: Chrome: 144.0.7559.132 Firefox Developer Edition: 148.0 Safari: 26.2 npmPackages: vite: ^7.2.4 => 7.3.1Used Package Manager
npm
Logs
No response
Validations