Skip to content

Commit bae52b5

Browse files
SveLilhi-ogawa
andauthored
fix(vm): fix external module resolve error with deps optimizer query for encoded URI [backport to v4] (#10661)
Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com>
1 parent f911144 commit bae52b5

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

packages/vitest/src/runtime/moduleRunner/cachedResolver.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { WorkerGlobalState } from '../../types/worker'
22
import { pathToFileURL } from 'node:url'
3+
import { splitFileAndPostfix } from '@vitest/utils/helpers'
34
import { join, normalize } from 'pathe'
45
import { distDir } from '../../paths'
56

@@ -25,9 +26,10 @@ export function getCachedVitestImport(
2526
const root = state().config.root
2627
const relativeRoot = relativeIds[root] ?? (relativeIds[root] = normalizedDistDir.slice(root.length))
2728
if (id.includes(distDir) || id.includes(normalizedDistDir)) {
29+
const { file, postfix } = splitFileAndPostfix(id)
2830
const externalize = id.startsWith('file://')
2931
? id
30-
: pathToFileURL(id).toString()
32+
: `${pathToFileURL(file)}${postfix}`
3133
externalizeMap.set(id, externalize)
3234
return { externalize, type: 'module' }
3335
}
@@ -36,8 +38,9 @@ export function getCachedVitestImport(
3638
// /node_modules/.pnpm/vitest/dist
3739
(relativeRoot && relativeRoot !== '/' && id.startsWith(relativeRoot))
3840
) {
39-
const path = join(root, id)
40-
const externalize = pathToFileURL(path).toString()
41+
const { file, postfix } = splitFileAndPostfix(id)
42+
const path = join(root, file)
43+
const externalize = `${pathToFileURL(path)}${postfix}`
4144
externalizeMap.set(id, externalize)
4245
return { externalize, type: 'module' }
4346
}

0 commit comments

Comments
 (0)