Skip to content

[v8] The hook generateBundle returns code stripped of directives, comments and unused variables #22096

Description

@ematipico

Describe the bug

When a virtual module contains comments, directives, and unused variables, those are removed from the code that is available in the hook generateBundle.

This is a regression compared to v7, and undocumented breaking change from the migration guide.

At Astro, we rely on a top-level comment to use our head propagation strategy, however this breaks in v8 because the comment is stripped.

Previous issue #21814

Reproduction

https://github.com/ematipico/test-errors/tree/bug/stripping-correct

Steps to reproduce

  • Checkout the repro
  • Checkout branch bug/stripping-correct
  • Run node build.mjs for single execution or run node build.mjs compare to compare v7 and v8

The output should show enough information

System Info

System:
    OS: macOS 26.4
    CPU: (12) arm64 Apple M4 Pro
    Memory: 3.67 GB / 48.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.12.0 - 
    npm: 11.6.2 - 
    pnpm: 10.28.0 - 
  Browsers:
    Firefox: 149.0
    Safari: 26.4
  npmPackages:
    vite: ^8.0.3 => 8.0.3

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions