Skip to content

Commit 1597170

Browse files
authored
fix(ssr): check esm file with normal file path (#15307)
1 parent 103820f commit 1597170

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

packages/vite/src/node/ssr/ssrModuleLoader.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,8 @@ async function nodeImport(
291291
metadata?: SSRImportMetadata,
292292
) {
293293
let url: string
294-
const isRuntimeHandled = id.startsWith('data:') || isBuiltin(id)
295-
if (isRuntimeHandled) {
294+
let filePath: string | undefined
295+
if (id.startsWith('data:') || isBuiltin(id)) {
296296
url = id
297297
} else {
298298
const resolved = tryNodeResolve(
@@ -310,24 +310,25 @@ async function nodeImport(
310310
err.code = 'ERR_MODULE_NOT_FOUND'
311311
throw err
312312
}
313+
filePath = resolved.id
313314
url = pathToFileURL(resolved.id).toString()
314315
}
315316

316317
const mod = await import(url)
317318

318319
if (resolveOptions.legacyProxySsrExternalModules) {
319320
return proxyESM(mod)
320-
} else if (isRuntimeHandled) {
321-
return mod
322-
} else {
321+
} else if (filePath) {
323322
analyzeImportedModDifference(
324323
mod,
325-
url,
324+
filePath,
326325
id,
327326
metadata,
328327
resolveOptions.packageCache,
329328
)
330329
return proxyGuardOnlyEsm(mod, id)
330+
} else {
331+
return mod
331332
}
332333
}
333334

0 commit comments

Comments
 (0)