@@ -3083,6 +3083,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
30833083 return ;
30843084 }
30853085
3086+ std::string package_initial_file = " " ;
3087+
30863088 ada::result<ada::url_aggregator> file_path_url;
30873089 std::optional<std::string> initial_file_path;
30883090 std::string file_path;
@@ -3105,6 +3107,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
31053107
31063108 FromNamespacedPath (&initial_file_path.value ());
31073109
3110+ package_initial_file = *initial_file_path;
3111+
31083112 for (int i = 0 ; i < legacy_main_extensions_with_main_end; i++) {
31093113 file_path = *initial_file_path + std::string (legacy_main_extensions[i]);
31103114
@@ -3160,13 +3164,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
31603164 }
31613165 }
31623166
3163- std::optional<std::string> module_path =
3164- node::url::FileURLToPath (env, *package_json_url);
3165- std::optional<std::string> module_base;
3167+ if (package_initial_file == " " )
3168+ package_initial_file = *initial_file_path + " .js" ;
31663169
3167- if (!module_path.has_value ()) {
3168- return ;
3169- }
3170+ std::optional<std::string> module_base;
31703171
31713172 if (args.Length () >= 3 && args[2 ]->IsString ()) {
31723173 Utf8Value utf8_base_path (isolate, args[2 ]);
@@ -3191,7 +3192,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
31913192
31923193 THROW_ERR_MODULE_NOT_FOUND (isolate,
31933194 " Cannot find package '%s' imported from %s" ,
3194- *module_path ,
3195+ package_initial_file ,
31953196 *module_base);
31963197}
31973198
0 commit comments