@@ -3143,6 +3143,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
31433143 return ;
31443144 }
31453145
3146+ std::string package_initial_file = " " ;
3147+
31463148 ada::result<ada::url_aggregator> file_path_url;
31473149 std::optional<std::string> initial_file_path;
31483150 std::string file_path;
@@ -3165,6 +3167,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
31653167
31663168 node::url::FromNamespacedPath (&initial_file_path.value ());
31673169
3170+ package_initial_file = *initial_file_path;
3171+
31683172 for (int i = 0 ; i < legacy_main_extensions_with_main_end; i++) {
31693173 file_path = *initial_file_path + std::string (legacy_main_extensions[i]);
31703174
@@ -3220,13 +3224,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
32203224 }
32213225 }
32223226
3223- std::optional<std::string> module_path =
3224- node::url::FileURLToPath (env, *package_json_url);
3225- std::optional<std::string> module_base;
3227+ if (package_initial_file == " " )
3228+ package_initial_file = *initial_file_path + " .js" ;
32263229
3227- if (!module_path.has_value ()) {
3228- return ;
3229- }
3230+ std::optional<std::string> module_base;
32303231
32313232 if (args.Length () >= 3 && args[2 ]->IsString ()) {
32323233 Utf8Value utf8_base_path (isolate, args[2 ]);
@@ -3251,7 +3252,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
32513252
32523253 THROW_ERR_MODULE_NOT_FOUND (isolate,
32533254 " Cannot find package '%s' imported from %s" ,
3254- *module_path ,
3255+ package_initial_file ,
32553256 *module_base);
32563257}
32573258
0 commit comments