@@ -227,9 +227,15 @@ const encodedSepRegEx = /%2F|%5C/i;
227227 */
228228function finalizeResolution ( resolved , base , preserveSymlinks ) {
229229 if ( RegExpPrototypeExec ( encodedSepRegEx , resolved . pathname ) !== null ) {
230+ let basePath ;
231+ try {
232+ basePath = fileURLToPath ( base ) ;
233+ } catch {
234+ basePath = base ;
235+ }
230236 throw new ERR_INVALID_MODULE_SPECIFIER (
231237 resolved . pathname , 'must not include encoded "/" or "\\" characters' ,
232- fileURLToPath ( base ) ) ;
238+ basePath ) ;
233239 }
234240
235241 let path ;
@@ -248,14 +254,26 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
248254
249255 // Check for stats.isDirectory()
250256 if ( stats === 1 ) {
251- throw new ERR_UNSUPPORTED_DIR_IMPORT ( path , fileURLToPath ( base ) , String ( resolved ) ) ;
257+ let basePath ;
258+ try {
259+ basePath = fileURLToPath ( base ) ;
260+ } catch {
261+ basePath = base ;
262+ }
263+ throw new ERR_UNSUPPORTED_DIR_IMPORT ( path , basePath , String ( resolved ) ) ;
252264 } else if ( stats !== 0 ) {
253265 // Check for !stats.isFile()
254266 if ( process . env . WATCH_REPORT_DEPENDENCIES && process . send ) {
255267 process . send ( { 'watch:require' : [ path || resolved . pathname ] } ) ;
256268 }
269+ let basePath ;
270+ try {
271+ basePath = fileURLToPath ( base ) ;
272+ } catch {
273+ basePath = base ;
274+ }
257275 throw new ERR_MODULE_NOT_FOUND (
258- path || resolved . pathname , base && fileURLToPath ( base ) , resolved ) ;
276+ path || resolved . pathname , basePath , resolved ) ;
259277 }
260278
261279 if ( ! preserveSymlinks ) {
0 commit comments