@@ -21,6 +21,9 @@ import { getDepsOptimizer } from '../optimizer'
21
21
import { injectSourcesContent } from './sourcemap'
22
22
import { isFileServingAllowed } from './middlewares/static'
23
23
24
+ export const ERR_LOAD_URL = 'ERR_LOAD_URL'
25
+ export const ERR_LOAD_PUBLIC_URL = 'ERR_LOAD_PUBLIC_URL'
26
+
24
27
const debugLoad = createDebugger ( 'vite:load' )
25
28
const debugTransform = createDebugger ( 'vite:transform' )
26
29
const debugCache = createDebugger ( 'vite:cache' )
@@ -215,18 +218,18 @@ async function loadAndTransform(
215
218
}
216
219
}
217
220
if ( code == null ) {
218
- if ( checkPublicFile ( url , config ) ) {
219
- throw new Error (
220
- `Failed to load url ${ url } (resolved id: ${ id } ). ` +
221
- `This file is in /public and will be copied as-is during build without ` +
222
- `going through the plugin transforms, and therefore should not be ` +
223
- `imported from source code. It can only be referenced via HTML tags.`
224
- )
225
- } else {
226
- return null
227
- }
221
+ const isPublicFile = checkPublicFile ( url , config )
222
+ const msg = isPublicFile
223
+ ? `This file is in /public and will be copied as-is during build without ` +
224
+ `going through the plugin transforms, and therefore should not be ` +
225
+ `imported from source code. It can only be referenced via HTML tags.`
226
+ : `Does the file exist?`
227
+ const err : any = new Error (
228
+ `Failed to load url ${ url } (resolved id: ${ id } ). ${ msg } `
229
+ )
230
+ err . code = isPublicFile ? ERR_LOAD_PUBLIC_URL : ERR_LOAD_URL
231
+ throw err
228
232
}
229
-
230
233
// ensure module in graph after successful load
231
234
const mod = await moduleGraph . ensureEntryFromUrl ( url , ssr )
232
235
ensureWatchedFile ( watcher , mod . file , root )
0 commit comments