@@ -1291,15 +1291,24 @@ static bool IsDocumentsPath(const std::string& path) {
12911291 absPath = builtinPath;
12921292 }
12931293 } else if (IsLikelyOptionalModule (spec)) {
1294- // Create a placeholder file on disk that bundler can resolve to
1294+ // In debug/test builds, surface a clear unresolved bare specifier error instead of
1295+ // synthesizing a placeholder module; more helpful signal during development.
1296+ if (RuntimeConfig.IsDebug ) {
1297+ std::string msg = " Cannot resolve bare specifier '" + spec + " '" ;
1298+ isolate->ThrowException (v8::Exception::Error (tns::ToV8String (isolate, msg.c_str ())));
1299+ return v8::MaybeLocal<v8::Module>();
1300+ }
1301+
1302+ // In release builds, create a placeholder that throws on use,
1303+ // so apps can guard optional imports without crashing at import time.
12951304 std::string appPath = RuntimeConfig.ApplicationPath ;
12961305 std::string placeholderPath = NormalizePath (appPath + " /" + spec + " .mjs" );
12971306
12981307 // Check if placeholder file already exists
12991308 if (!isFile (placeholderPath)) {
13001309 // Create placeholder content
1301- std::string placeholderContent = " const error = new Error('Module \\ '" + spec +
1302- " \\ ' is not available. This is an optional module.');\n "
1310+ std::string placeholderContent = " const error = new Error('Module \\\ ' " + spec +
1311+ " \\\ ' is not available. This is an optional module.');\n "
13031312 " const proxy = new Proxy({}, {\n "
13041313 " get: function(target, prop) { throw error; },\n "
13051314 " set: function(target, prop, value) { throw error; },\n "
@@ -1323,14 +1332,8 @@ static bool IsDocumentsPath(const std::string& path) {
13231332 } else {
13241333 // Failed to create file, fall back to throwing error
13251334 std::string msg = " Cannot find module " + spec + " (tried " + absPath + " )" ;
1326- if (RuntimeConfig.IsDebug ) {
1327- Log (@" Debug mode - Optional module placeholder creation failed: %s " , msg.c_str ());
1328- // Return empty instead of crashing in debug mode
1329- return v8::MaybeLocal<v8::Module>();
1330- } else {
1331- isolate->ThrowException (v8::Exception::Error (tns::ToV8String (isolate, msg)));
1332- return v8::MaybeLocal<v8::Module>();
1333- }
1335+ isolate->ThrowException (v8::Exception::Error (tns::ToV8String (isolate, msg)));
1336+ return v8::MaybeLocal<v8::Module>();
13341337 }
13351338 } else {
13361339 // Placeholder file already exists, use it
0 commit comments