@@ -3143,6 +3143,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
3143
3143
return ;
3144
3144
}
3145
3145
3146
+ std::string package_initial_file = " " ;
3147
+
3146
3148
ada::result<ada::url_aggregator> file_path_url;
3147
3149
std::optional<std::string> initial_file_path;
3148
3150
std::string file_path;
@@ -3165,6 +3167,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
3165
3167
3166
3168
node::url::FromNamespacedPath (&initial_file_path.value ());
3167
3169
3170
+ package_initial_file = *initial_file_path;
3171
+
3168
3172
for (int i = 0 ; i < legacy_main_extensions_with_main_end; i++) {
3169
3173
file_path = *initial_file_path + std::string (legacy_main_extensions[i]);
3170
3174
@@ -3220,13 +3224,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
3220
3224
}
3221
3225
}
3222
3226
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" ;
3226
3229
3227
- if (!module_path.has_value ()) {
3228
- return ;
3229
- }
3230
+ std::optional<std::string> module_base;
3230
3231
3231
3232
if (args.Length () >= 3 && args[2 ]->IsString ()) {
3232
3233
Utf8Value utf8_base_path (isolate, args[2 ]);
@@ -3251,7 +3252,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
3251
3252
3252
3253
THROW_ERR_MODULE_NOT_FOUND (isolate,
3253
3254
" Cannot find package '%s' imported from %s" ,
3254
- *module_path ,
3255
+ package_initial_file ,
3255
3256
*module_base);
3256
3257
}
3257
3258
0 commit comments