Skip to content

buildStart behavior change in Vite 6 can cause vite optimize to hang #19316

@ef4

Description

@ef4

Describe the bug

Under Vite 5, a plugin's buildStart doesn't run during vite optimize.

Under Vite 6 it does, as a side-effect of environment.init() being introduced in optimizeDeps().

And since vite optimize rather confusingly uses command === 'serve' here, plugins now have no way of knowing whether their buildStart is running in vite dev vs vite optimize.

As a result, plugins that want to manage a dev-time background task will launch that task during vite optimize and can cause node to refuse to exit, since they think they are supposed to keep serving content.

Reproduction

https://stackblitz.com/edit/vitejs-vite-ncfab2z9?file=vite.config.js

Steps to reproduce

The linked stackbliz has a minimal reproduction. Run vite optimize and observe that the process refuses to exit.

You can repeat the same vite.config.js on Vite 5.x and observe that vite optimize no longer hangs.

System Info

N/A

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-downstream-blockerBlocking the downstream ecosystem to work properly (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions