@@ -37,7 +37,7 @@ const experimentalNetworkImports =
3737 getOptionValue ( '--experimental-network-imports' ) ;
3838const inputTypeFlag = getOptionValue ( '--input-type' ) ;
3939const { URL , pathToFileURL, fileURLToPath, isURL } = require ( 'internal/url' ) ;
40- const { getCWDURL, setOwnProperty } = require ( 'internal/util' ) ;
40+ const { getCWDURL } = require ( 'internal/util' ) ;
4141const { canParse : URLCanParse } = internalBinding ( 'url' ) ;
4242const { legacyMainResolve : FSLegacyMainResolve } = internalBinding ( 'fs' ) ;
4343const {
@@ -897,26 +897,21 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
897897 // Ok since relative URLs cannot parse as URLs.
898898 let resolved ;
899899 if ( shouldBeTreatedAsRelativeOrAbsolutePath ( specifier ) ) {
900- try {
901- resolved = new URL ( specifier , base ) ;
902- } catch ( cause ) {
903- const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST ( specifier , base ) ;
904- setOwnProperty ( error , 'cause' , cause ) ;
905- throw error ;
900+ resolved = URL . parse ( specifier , base ) ;
901+
902+ if ( resolved == null ) {
903+ throw new ERR_UNSUPPORTED_RESOLVE_REQUEST ( specifier , base ) ;
906904 }
907905 } else if ( protocol === 'file:' && specifier [ 0 ] === '#' ) {
908906 resolved = packageImportsResolve ( specifier , base , conditions ) ;
909907 } else {
910- try {
911- resolved = new URL ( specifier ) ;
912- } catch ( cause ) {
913- if ( isRemote && ! BuiltinModule . canBeRequiredWithoutScheme ( specifier ) ) {
914- const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST ( specifier , base ) ;
915- setOwnProperty ( error , 'cause' , cause ) ;
916- throw error ;
917- }
918- resolved = packageResolve ( specifier , base , conditions ) ;
908+ resolved = URL . parse ( specifier ) ;
909+
910+ if ( resolved == null && isRemote && ! BuiltinModule . canBeRequiredWithoutScheme ( specifier ) ) {
911+ throw new ERR_UNSUPPORTED_RESOLVE_REQUEST ( specifier , base ) ;
919912 }
913+
914+ resolved ??= packageResolve ( specifier , base , conditions ) ;
920915 }
921916 if ( resolved . protocol !== 'file:' ) {
922917 return resolved ;
@@ -1082,11 +1077,7 @@ function defaultResolve(specifier, context = {}) {
10821077
10831078 let parsedParentURL ;
10841079 if ( parentURL ) {
1085- try {
1086- parsedParentURL = new URL ( parentURL ) ;
1087- } catch {
1088- // Ignore exception
1089- }
1080+ parsedParentURL = URL . parse ( parentURL ) ;
10901081 }
10911082
10921083 let parsed , protocol ;
0 commit comments