Description
Describe the bug
I am building a test runner script for my webapp in react.
It's an iterative "looping" scripts that runs the webapp over multiple times.
The first 3 times i need to do a quick test, then test should be long afterwards.
When i run the project npm run dev
- basically just "vite" command, the first 3 test are running quickly, then the rest are slow - so my TS files seem to work in development.
When i run build the project npm run build
- "tsc && vite build" command, and then host that webapp and open it, the every test is quick - not like in development.
- i see in my build js file that i cannot find some of the variables associated with my quick test evaluation nor the implementation of those missing variables (e,g. used in shorthand if/else operations like
const quickTestTime = isQuickTest ? (5 * 60 * 1000) / 15 : 5 * 60 * 1000
but it then showsconst quickTestTime = (5 * 60 * 1000) / 15
instead so the "isQuickTest" variable gets stripped away and the logical operations for it.
if i run tsc myfile.ts
everything compiles til JS perfectly. if i run npm run dev, i get no runtime errors & the ts seems to work perfectly as expected. theres no build errors but for whatever reason something that works in production and that tsc can compile perfectly to JS gets stripped out from vite build process - leaving me no errors to investigate, so i just used a shitload of time finding this issue.
I know why it could make sense for the build process to strip it out - it evaluates to true || 1, so the variable as well as the condition is "not needed" from a programatic view, but from a developer / intended view in my opinion it is verry bad DevEx to strip out conditional statements with no warnings
Reproduction
https://stackblitz.com/edit/vitejs-vite-9y8hev2g?file=build%2Fassets%2Findex-CZk89dWW.js
Steps to reproduce
in the reproduction site,
npm uninstall tsc
npm install typescript
npm run build
view the build js file and see that RunTestFails() function is missing quicktesttime var and implementations
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
vite: ^7.0.0-beta.1 => 7.0.0-beta.2
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.