@@ -3185,6 +3185,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
31853185 return ;
31863186 }
31873187
3188+ std::string package_initial_file = " " ;
3189+
31883190 ada::result<ada::url_aggregator> file_path_url;
31893191 std::optional<std::string> initial_file_path;
31903192 std::string file_path;
@@ -3207,6 +3209,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
32073209
32083210 FromNamespacedPath (&initial_file_path.value ());
32093211
3212+ package_initial_file = *initial_file_path;
3213+
32103214 for (int i = 0 ; i < legacy_main_extensions_with_main_end; i++) {
32113215 file_path = *initial_file_path + std::string (legacy_main_extensions[i]);
32123216
@@ -3262,13 +3266,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
32623266 }
32633267 }
32643268
3265- std::optional<std::string> module_path =
3266- node::url::FileURLToPath (env, *package_json_url);
3267- std::optional<std::string> module_base;
3269+ if (package_initial_file == " " )
3270+ package_initial_file = *initial_file_path + " .js" ;
32683271
3269- if (!module_path.has_value ()) {
3270- return ;
3271- }
3272+ std::optional<std::string> module_base;
32723273
32733274 if (args.Length () >= 3 && args[2 ]->IsString ()) {
32743275 Utf8Value utf8_base_path (isolate, args[2 ]);
@@ -3293,7 +3294,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
32933294
32943295 THROW_ERR_MODULE_NOT_FOUND (isolate,
32953296 " Cannot find package '%s' imported from %s" ,
3296- *module_path ,
3297+ package_initial_file ,
32973298 *module_base);
32983299}
32993300
0 commit comments