Skip to content

[🐞BUG]: import.meta.env.PROD has the wrong value, even if stubbed. #5525

@xsjcTony

Description

@xsjcTony

Describe the bug

import.meta.env.PROD will always have the value true.
It will only be false if I stub it to empty string '', but that's definitely not ideal.
Seems there's an issue when converting the string into a boolean (maybe !! is used straight away without checking for special value e.g. string 'false')
I don't have enough time to find the regression commit (it's working as expected before) and the exact logic in the code base, but please get this fixed, thanks🙏

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-ckneff?file=test%2Fbasic.test.ts

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 5.85 GB / 31.69 GB
  Binaries:
    Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.6.9 - ~\AppData\Local\pnpm\pnpm.EXE
  Browsers:
    Edge: Chromium (123.0.2420.81)
    Internet Explorer: 11.0.22621.1
  npmPackages:
    @vitejs/plugin-react-swc: ^3.6.0 => 3.6.0
    @vitest/coverage-istanbul: ^1.5.0 => 1.5.0
    @vitest/coverage-v8: ^1.5.0 => 1.5.0
    @vitest/ui: ^1.5.0 => 1.5.0
    vite: ^5.2.8 => 5.2.8
    vitest: ^1.5.0 => 1.5.0

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions