Skip to content

Astro 6.0.5+ dev error: context method emitFile() is not supported in serve mode. #16026

@anaxite

Description

@anaxite

Astro Info

Astro                    v6.0.8
Node                     v24.14.0
System                   Linux (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             @astrojs/react
                         @astrojs/mdx
                         @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Summary

When using astro dev for Astro 6.0.5+, the command may output a Vite warning with certain plugins:

[WARN] [vite] [plugin:astro:scripts] context method emitFile() is not supported in serve mode. This plugin is likely not vite-compatible.

Steps to reproduce

  1. Clone https://github.com/southwellmedia/velocity
  2. In package.json, set the Astro version to 6.0.5 or later
  3. Run pnpm update
  4. Run pnpm dev. The error appears

Details

I was using the Astro template https://github.com/southwellmedia/velocity. When I updated it from Astro 6.0.4 to 6.0.5, the Vite warning started appearing.

Requested an analysis from Claude, which responded as follows:

● Root Cause                                                                                             
                                                                                              
  The warning comes from Astro's own internal vite-plugin-scripts — nothing in your project config is wrong.           
                                         
  What changed in 6.0.5: PR #15904 fixed a bug where the before-hydration script chunk wasn't being emitted for the    
  client Vite environment. The fix added an this.emitFile() call in buildStart() for the client environment. However,  
  buildStart() also runs during dev, and emitFile() is a Rollup build-time API that Vite stubs out in serve mode —     
  hence the warning.                                                                                                   
                                                                                                                       
  In 6.0.4, the client environment was accidentally excluded from that emitFile() call (the bug), so no warning        
  appeared. The 6.0.5 fix is correct for production builds but introduces this cosmetic dev warning.
                                                                                                                       
  Why your project triggers it: You use @astrojs/react with hydration directives (client:load, client:visible, etc.),  
  which relies on the before-hydration script path.                                                                    
                                                                                                                       
  Impact: The warning is harmless — dev and production builds both work correctly. It needs an upstream fix in Astro   
  (guarding emitFile() to only run during build, not serve)

What's the expected result?

No warning appears.

Link to Minimal Reproducible Example

https://github.com/southwellmedia/velocity

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

- P3: minor bugAn edge case that only affects very specific usage (priority)pkg: astroRelated to the core `astro` package (scope)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions