@@ -33,8 +33,8 @@ const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main');
3333const experimentalNetworkImports =
3434 getOptionValue ( '--experimental-network-imports' ) ;
3535const inputTypeFlag = getOptionValue ( '--input-type' ) ;
36- const { URL , pathToFileURL, fileURLToPath, isURL } = require ( 'internal/url' ) ;
37- const { getCWDURL, setOwnProperty } = require ( 'internal/util' ) ;
36+ const { URL , pathToFileURL, fileURLToPath, isURL, URLParse } = require ( 'internal/url' ) ;
37+ const { getCWDURL } = require ( 'internal/util' ) ;
3838const { canParse : URLCanParse } = internalBinding ( 'url' ) ;
3939const { legacyMainResolve : FSLegacyMainResolve } = internalBinding ( 'fs' ) ;
4040const {
@@ -893,26 +893,21 @@ function moduleResolve(specifier, base, conditions, preserveSymlinks) {
893893 // Ok since relative URLs cannot parse as URLs.
894894 let resolved ;
895895 if ( shouldBeTreatedAsRelativeOrAbsolutePath ( specifier ) ) {
896- try {
897- resolved = new URL ( specifier , base ) ;
898- } catch ( cause ) {
899- const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST ( specifier , base ) ;
900- setOwnProperty ( error , 'cause' , cause ) ;
901- throw error ;
896+ resolved = URL . parse ( specifier , base ) ;
897+
898+ if ( resolved == null ) {
899+ throw new ERR_UNSUPPORTED_RESOLVE_REQUEST ( specifier , base ) ;
902900 }
903901 } else if ( protocol === 'file:' && specifier [ 0 ] === '#' ) {
904902 resolved = packageImportsResolve ( specifier , base , conditions ) ;
905903 } else {
906- try {
907- resolved = new URL ( specifier ) ;
908- } catch ( cause ) {
909- if ( isRemote && ! BuiltinModule . canBeRequiredWithoutScheme ( specifier ) ) {
910- const error = new ERR_UNSUPPORTED_RESOLVE_REQUEST ( specifier , base ) ;
911- setOwnProperty ( error , 'cause' , cause ) ;
912- throw error ;
913- }
914- resolved = packageResolve ( specifier , base , conditions ) ;
904+ resolved = URL . parse ( specifier ) ;
905+
906+ if ( resolved == null && isRemote && ! BuiltinModule . canBeRequiredWithoutScheme ( specifier ) ) {
907+ throw new ERR_UNSUPPORTED_RESOLVE_REQUEST ( specifier , base ) ;
915908 }
909+
910+ resolved ??= packageResolve ( specifier , base , conditions ) ;
916911 }
917912 if ( resolved . protocol !== 'file:' ) {
918913 return resolved ;
@@ -1053,11 +1048,7 @@ function defaultResolve(specifier, context = {}) {
10531048
10541049 let parsedParentURL ;
10551050 if ( parentURL ) {
1056- try {
1057- parsedParentURL = new URL ( parentURL ) ;
1058- } catch {
1059- // Ignore exception
1060- }
1051+ parsedParentURL = URL . parse ( parentURL ) ;
10611052 }
10621053
10631054 let parsed , protocol ;
0 commit comments