Skip to content

fix(build): avoid redefining viteMetadata on chunk#21470

Closed
Avinash99b wants to merge 1 commit intovitejs:mainfrom
Avinash99b:main
Closed

fix(build): avoid redefining viteMetadata on chunk#21470
Avinash99b wants to merge 1 commit intovitejs:mainfrom
Avinash99b:main

Conversation

@Avinash99b
Copy link
Copy Markdown

This PR fixes the build failure reported in #21466, where Vite 8.0.0-beta.9 crashes during build with:

TypeError: Cannot redefine property: viteMetadata

This occurs when using Nitro/TanStack Start, where the same chunk object may be processed more than once during output normalization with the Rolldown-based pipeline.

Root Cause

injectChunkMetadata previously unconditionally defined the viteMetadata property on the chunk using Object.defineProperty. When the function is re-entered for the same chunk, redefining the property throws at runtime.

Fix

The metadata injection is now guarded so the property is only defined if it does not already exist. This makes the operation idempotent while preserving existing behavior for builds where chunks are processed only once.

- Object.defineProperty(chunk, 'viteMetadata', {
-   value: chunkMetadataMap.get(chunk),
-   enumerable: true,
- })
+ if (!('viteMetadata' in chunk)) {
+   Object.defineProperty(chunk, 'viteMetadata', {
+     value: chunkMetadataMap.get(chunk),
+     enumerable: true,
+   })
+ }

Impact

  • Fixes the crash in Vite 8.0.0-beta.9 when used with Nitro-based setups
  • No public API changes
  • No behavior changes for Rollup-style single-pass builds
  • Improves robustness for re-entrant chunk normalization in the Rolldown pipeline

Closes #21466.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vite 8.0.0-beta.9 builds failing tanstack/nitro

1 participant