Skip to content

Commit 1b211fd

Browse files
authored
fix(asset): only watch existing files for new URL(, import.meta.url) (vitejs#20507)
1 parent 3676da5 commit 1b211fd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/vite/src/node/plugins/assetImportMetaUrl.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
isDataUrl,
1010
isParentDirectory,
1111
transformStableResult,
12+
tryStatSync,
1213
} from '../utils'
1314
import { CLIENT_ENTRY } from '../constants'
1415
import { slash } from '../../shared/utils'
@@ -142,8 +143,11 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
142143
const publicPath = '/' + path.posix.relative(publicDir, file)
143144
builtUrl = await fileToUrl(this, publicPath)
144145
} else {
145-
this.addWatchFile(file)
146146
builtUrl = await fileToUrl(this, file)
147+
// during dev, builtUrl may point to a directory or a non-existing file
148+
if (tryStatSync(file)?.isFile()) {
149+
this.addWatchFile(file)
150+
}
147151
}
148152
} catch {
149153
// do nothing, we'll log a warning after this

0 commit comments

Comments
 (0)