@@ -87,8 +87,15 @@ static bool IsNodeBuiltinModule(const std::string& moduleName) {
87
87
// would need the referrer's directory to resolve it.
88
88
bool specIsRelative = !spec.empty () && spec[0 ] == ' .' ;
89
89
if (referrerPath.empty () && specIsRelative) {
90
- // Unable to resolve a relative path without knowing the base directory.
91
- return v8::MaybeLocal<v8::Module>();
90
+ // For dynamic imports, assume the base directory is the application root
91
+ // This handles cases where runtime.mjs calls import("./chunk.mjs")
92
+ // but the referrer module isn't properly registered
93
+ if (IsScriptLoadingLogEnabled ()) {
94
+ NSLog (@" [resolver] No referrer found for relative import '%s ', assuming app root" ,
95
+ spec.c_str());
96
+ }
97
+ referrerPath =
98
+ RuntimeConfig.ApplicationPath + " /runtime.mjs" ; // Default to runtime.mjs as referrer
92
99
}
93
100
94
101
// 3) Compute its directory
@@ -110,7 +117,13 @@ static bool IsNodeBuiltinModule(const std::string& moduleName) {
110
117
if (!spec.empty () && spec[0 ] == ' .' ) {
111
118
// Relative import (./ or ../)
112
119
std::string cleanSpec = spec.rfind (" ./" , 0 ) == 0 ? spec.substr (2 ) : spec;
113
- candidateBases.push_back (baseDir + cleanSpec);
120
+ std::string candidate = baseDir + cleanSpec;
121
+ candidateBases.push_back (candidate);
122
+
123
+ if (IsScriptLoadingLogEnabled ()) {
124
+ NSLog (@" [resolver] Relative import: '%s ' + '%s ' -> '%s '" , baseDir.c_str(), cleanSpec.c_str(),
125
+ candidate.c_str());
126
+ }
114
127
} else if (spec.rfind (" file://" , 0 ) == 0 ) {
115
128
// Absolute file URL, e.g. file:///app/path/to/chunk.mjs
116
129
std::string tail = spec.substr (7 ); // strip file://
@@ -149,7 +162,7 @@ static bool IsNodeBuiltinModule(const std::string& moduleName) {
149
162
std::string base = RuntimeConfig.ApplicationPath + " /" + spec;
150
163
candidateBases.push_back (base);
151
164
152
- // Additional heuristic: Webpack encodes path separators as underscores in
165
+ // Additional heuristic: bundlers often encode path separators as underscores in
153
166
// chunk IDs (e.g. "src_app_components_foo_bar_ts.mjs"). Try converting
154
167
// those underscores back to slashes and look for that file as well.
155
168
std::string withSlashes = spec;
@@ -295,7 +308,7 @@ static bool IsNodeBuiltinModule(const std::string& moduleName) {
295
308
absPath = builtinPath;
296
309
}
297
310
} else if (IsLikelyOptionalModule (spec)) {
298
- // Create a placeholder file on disk that webpack can resolve to
311
+ // Create a placeholder file on disk that bundler can resolve to
299
312
std::string appPath = RuntimeConfig.ApplicationPath ;
300
313
std::string placeholderPath = appPath + " /" + spec + " .mjs" ;
301
314
@@ -494,7 +507,7 @@ static bool IsNodeBuiltinModule(const std::string& moduleName) {
494
507
}
495
508
}
496
509
497
- // Special handling for webpack chunks: check if this is a webpack chunk and install it
510
+ // Special handling for bundler chunks: check if this is a bundler chunk and install it
498
511
v8::Local<v8::Value> namespaceObj = module ->GetModuleNamespace ();
499
512
if (namespaceObj->IsObject ()) {
500
513
v8::Local<v8::Object> nsObj = namespaceObj.As <v8::Object>();
0 commit comments