From 4339bdb8dbb7c26eaff2ea51a770fda991925b40 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Wed, 30 Jul 2025 20:36:29 +0900 Subject: [PATCH] fix(asset): only watch existing files for `new URL(, import.meta.url)` --- packages/vite/src/node/plugins/assetImportMetaUrl.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/assetImportMetaUrl.ts b/packages/vite/src/node/plugins/assetImportMetaUrl.ts index 37aef68c303ad5..74af98cc62a6f0 100644 --- a/packages/vite/src/node/plugins/assetImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/assetImportMetaUrl.ts @@ -9,6 +9,7 @@ import { isDataUrl, isParentDirectory, transformStableResult, + tryStatSync, } from '../utils' import { CLIENT_ENTRY } from '../constants' import { slash } from '../../shared/utils' @@ -142,8 +143,11 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin { const publicPath = '/' + path.posix.relative(publicDir, file) builtUrl = await fileToUrl(this, publicPath) } else { - this.addWatchFile(file) builtUrl = await fileToUrl(this, file) + // during dev, builtUrl may point to a directory or a non-existing file + if (tryStatSync(file)?.isFile()) { + this.addWatchFile(file) + } } } catch { // do nothing, we'll log a warning after this