File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import getEtag from 'etag'
55import convertSourceMap from 'convert-source-map'
66import type { SourceDescription , SourceMap } from 'rollup'
77import colors from 'picocolors'
8- import type { ViteDevServer } from '..'
8+ import type { ModuleNode , ViteDevServer } from '..'
99import {
1010 blankReplacer ,
1111 cleanUrl ,
@@ -227,8 +227,15 @@ async function loadAndTransform(
227227 `going through the plugin transforms, and therefore should not be ` +
228228 `imported from source code. It can only be referenced via HTML tags.`
229229 : `Does the file exist?`
230+ const importerMod : ModuleNode | undefined = server . moduleGraph . idToModuleMap
231+ . get ( id )
232+ ?. importers . values ( )
233+ . next ( ) . value
234+ const importer = importerMod ?. file || importerMod ?. url
230235 const err : any = new Error (
231- `Failed to load url ${ url } (resolved id: ${ id } ). ${ msg } ` ,
236+ `Failed to load url ${ url } (resolved id: ${ id } )${
237+ importer ? ` in ${ importer } ` : ''
238+ } . ${ msg } `,
232239 )
233240 err . code = isPublicFile ? ERR_LOAD_PUBLIC_URL : ERR_LOAD_URL
234241 throw err
Original file line number Diff line number Diff line change 11import { fileURLToPath } from 'node:url'
2+ import path from 'node:path'
23import { expect , test } from 'vitest'
34import { createServer } from '../../server'
5+ import { normalizePath } from '../../utils'
46
57const root = fileURLToPath ( new URL ( './' , import . meta. url ) )
68
@@ -13,11 +15,13 @@ async function createDevServer() {
1315test ( 'ssrLoad' , async ( ) => {
1416 expect . assertions ( 1 )
1517 const server = await createDevServer ( )
18+ const moduleRelativePath = '/fixtures/modules/has-invalid-import.js'
19+ const moduleAbsolutePath = normalizePath ( path . join ( root , moduleRelativePath ) )
1620 try {
17- await server . ssrLoadModule ( '/fixtures/modules/has-invalid-import.js' )
21+ await server . ssrLoadModule ( moduleRelativePath )
1822 } catch ( e ) {
1923 expect ( e . message ) . toBe (
20- ' Failed to load url ./non-existent.js (resolved id: ./non-existent.js). Does the file exist?' ,
24+ ` Failed to load url ./non-existent.js (resolved id: ./non-existent.js) in ${ moduleAbsolutePath } . Does the file exist?` ,
2125 )
2226 }
2327} )
You can’t perform that action at this time.
0 commit comments