@@ -5,7 +5,7 @@ import type { VMModule } from './vm/types'
55import fs from 'node:fs'
66import { isBuiltin } from 'node:module'
77import { fileURLToPath , pathToFileURL } from 'node:url'
8- import { isBareImport } from '@vitest/utils/helpers'
8+ import { isBareImport , splitFileAndPostfix } from '@vitest/utils/helpers'
99import { findNearestPackageData } from '@vitest/utils/resolver'
1010import { extname , normalize } from 'pathe'
1111import { CommonjsExecutor } from './vm/commonjs-executor'
@@ -125,7 +125,8 @@ export class ExternalModulesExecutor {
125125 return { type : 'data' , url : identifier , path : identifier }
126126 }
127127
128- const extension = extname ( identifier )
128+ const { file, postfix } = splitFileAndPostfix ( identifier )
129+ const extension = extname ( file )
129130 if ( extension === '.node' || isBuiltin ( identifier ) ) {
130131 return { type : 'builtin' , url : identifier , path : identifier }
131132 }
@@ -138,10 +139,8 @@ export class ExternalModulesExecutor {
138139 }
139140
140141 const isFileUrl = identifier . startsWith ( 'file://' )
141- const pathUrl = isFileUrl
142- ? fileURLToPath ( identifier . split ( '?' ) [ 0 ] )
143- : identifier
144- const fileUrl = isFileUrl ? identifier : pathToFileURL ( pathUrl ) . toString ( )
142+ const pathUrl = isFileUrl ? fileURLToPath ( file ) : file
143+ const fileUrl = isFileUrl ? identifier : `${ pathToFileURL ( file ) } ${ postfix } `
145144
146145 let type : 'module' | 'commonjs' | 'vite' | 'wasm'
147146 if ( this . vite . canResolve ( fileUrl ) ) {
0 commit comments