File tree 2 files changed +15
-4
lines changed
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'
5
5
import convertSourceMap from 'convert-source-map'
6
6
import type { SourceDescription , SourceMap } from 'rollup'
7
7
import colors from 'picocolors'
8
- import type { ViteDevServer } from '..'
8
+ import type { ModuleNode , ViteDevServer } from '..'
9
9
import {
10
10
blankReplacer ,
11
11
cleanUrl ,
@@ -227,8 +227,15 @@ async function loadAndTransform(
227
227
`going through the plugin transforms, and therefore should not be ` +
228
228
`imported from source code. It can only be referenced via HTML tags.`
229
229
: `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
230
235
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 } `,
232
239
)
233
240
err . code = isPublicFile ? ERR_LOAD_PUBLIC_URL : ERR_LOAD_URL
234
241
throw err
Original file line number Diff line number Diff line change 1
1
import { fileURLToPath } from 'node:url'
2
+ import path from 'node:path'
2
3
import { expect , test } from 'vitest'
3
4
import { createServer } from '../../server'
5
+ import { normalizePath } from '../../utils'
4
6
5
7
const root = fileURLToPath ( new URL ( './' , import . meta. url ) )
6
8
@@ -13,11 +15,13 @@ async function createDevServer() {
13
15
test ( 'ssrLoad' , async ( ) => {
14
16
expect . assertions ( 1 )
15
17
const server = await createDevServer ( )
18
+ const moduleRelativePath = '/fixtures/modules/has-invalid-import.js'
19
+ const moduleAbsolutePath = normalizePath ( path . join ( root , moduleRelativePath ) )
16
20
try {
17
- await server . ssrLoadModule ( '/fixtures/modules/has-invalid-import.js' )
21
+ await server . ssrLoadModule ( moduleRelativePath )
18
22
} catch ( e ) {
19
23
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?` ,
21
25
)
22
26
}
23
27
} )
You can’t perform that action at this time.
0 commit comments