VITE0026Return only new array entries from Vite config hooks
Why it happens
Vite merges each config and configEnvironment hook result into the current config with mergeConfig, which concatenates arrays instead of replacing them. A hook that returns ...config.ssr.noExternal, 'my-package' therefore adds every existing entry a second time, and each plugin that does this doubles the entries of the plugins before it. Doctor reports a returned array at a config path that spreads or concatenates the incoming value at the same path, directly or through a helper function defined once in the same file that returns its parameter spread or concatenated. It does not follow helpers imported from other files, and it ignores hooks that assign to the incoming config in place. An object counts as a plugin when it has Vite plugin hooks such as configResolved or enforce, or when it has a name and the file imports or requires Vite, Vitest, Rollup, Rolldown, unplugin, or @nuxt/kit, or is a Vite config.
Fix
Return only the entries the plugin adds, skipping entries that are already present, or assign to the incoming config in place and leave that field out of the returned object.
Example
Return only the added entries
Before
export function dedupePlugin(): Plugin {
return {
name: 'dedupe-vue',
config(config) {
return {
resolve: { dedupe: [...(config.resolve?.dedupe ?? []), 'vue'] },
}
},
}
}
After
export function dedupePlugin(): Plugin {
return {
name: 'dedupe-vue',
config(config) {
if (config.resolve?.dedupe?.includes('vue')) return
return { resolve: { dedupe: ['vue'] } }
},
}
}
Verify the fix
Run only this rule after editing so the report stays focused on the diagnostic you are closing:
pnpm vite-doctor . --framework vite --rules vite/plugin/no-config-hook-array-echo