Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,8 @@ const configDefaults = Object.freeze({
// entries
/** @experimental */
force: false,
/** @experimental */
ignoreOutdatedRequests: false,
},
ssr: ssrConfigDefaults,
environments: {},
Expand Down
8 changes: 8 additions & 0 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ export interface DepOptimizationConfig {
* @experimental
*/
holdUntilCrawlEnd?: boolean
/**
* When enabled, Vite will not throw an error when an outdated optimized
* dependency is requested. Enabling this option may cause a single module
* to have a multiple reference.
* @default false
* @experimental
*/
ignoreOutdatedRequests?: boolean
}

export type DepOptimizationOptions = DepOptimizationConfig & {
Expand Down
16 changes: 13 additions & 3 deletions packages/vite/src/node/plugins/optimizedDeps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export function optimizedDepsPlugin(): Plugin {
// Search in both the currently optimized and newly discovered deps
const info = optimizedDepInfoFromFile(metadata, file)
if (info) {
if (browserHash && info.browserHash !== browserHash) {
if (
browserHash &&
info.browserHash !== browserHash &&
!environment.config.optimizeDeps.ignoreOutdatedRequests
) {
Comment on lines +53 to +57

@jamesopstad jamesopstad Jan 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the issue occurs but it seems best to apply the option in each of the places the error is thrown.

throwOutdatedRequest(id)
}
try {
Expand All @@ -65,7 +69,10 @@ export function optimizedDepsPlugin(): Plugin {
const newMetadata = depsOptimizer.metadata
if (metadata !== newMetadata) {
const currentInfo = optimizedDepInfoFromFile(newMetadata!, file)
if (info.browserHash !== currentInfo?.browserHash) {
if (
info.browserHash !== currentInfo?.browserHash &&
!environment.config.optimizeDeps.ignoreOutdatedRequests
) {
throwOutdatedRequest(id)
}
}
Expand All @@ -77,7 +84,10 @@ export function optimizedDepsPlugin(): Plugin {
try {
return await fsp.readFile(file, 'utf-8')
} catch {
if (browserHash) {
if (
browserHash &&
!environment.config.optimizeDeps.ignoreOutdatedRequests
) {
// Outdated optimized files loaded after a rerun
throwOutdatedRequest(id)
}
Expand Down