Skip to content

sourcemap is invalid when environment variables do not exist #15771

@Beiluola

Description

@Beiluola

Describe the bug

In the vitejs 5.0.12 documentation it was mentioned that environment variables would be replaced with undefined if they didn't exist, what I didn't expect was that this made sourcemap invalid. Maybe this is a feature rather than a bug. If that's the case, then I think it should be mentioned in the documentation, this saves developers time in locating problems.

Reproduction

https://stackblitz.com/edit/vitejs-vite-om3cbj?file=README.md&terminal=dev

Steps to reproduce

  1. open the project using vscode
  2. npm run build:env-sourcemap
  3. add a breakpoint in the ./src/env-not-exist.ts file
  4. open vscode javascript debugging terminal
  5. node ./dist/env-not-exist.cjs
  6. breakpoint not in effect
  7. repeat the above steps in ./dist/ env-existence.cjs and./src/env-exist.ts, no problem

System Info

System:
    OS: macOS 13.0
    CPU: (8) arm64 Apple M1
    Memory: 63.05 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.18.0 - ~/.nvm/versions/node/v16.18.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 8.19.4 - ~/.nvm/versions/node/v16.18.0/bin/npm
    pnpm: 8.10.2 - ~/.nvm/versions/node/v16.18.0/bin/pnpm
  Browsers:
    Safari: 16.1
  npmPackages:
    @vitejs/plugin-vue: ^4.5.2 => 4.6.2

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: sourcemapSourcemap supportp3-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