@@ -1291,16 +1291,9 @@ static bool IsDocumentsPath(const std::string& path) {
12911291 absPath = builtinPath;
12921292 }
12931293 } else if (IsLikelyOptionalModule (spec)) {
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.
1294+ // Treat bare specifiers as optional modules by creating a placeholder ES module that
1295+ // throws on property access. This lets applications guard optional imports at runtime
1296+ // without crashing during startup, especially in development.
13041297 std::string appPath = RuntimeConfig.ApplicationPath ;
13051298 std::string placeholderPath = NormalizePath (appPath + " /" + spec + " .mjs" );
13061299
@@ -1330,10 +1323,16 @@ static bool IsDocumentsPath(const std::string& path) {
13301323 // File created successfully, now resolve it normally
13311324 absPath = placeholderPath;
13321325 } else {
1333- // Failed to create file, fall back to throwing error
1326+ // Failed to create file. In debug, avoid throwing to keep dev sessions alive; in release
1327+ // throw to surface the missing optional module.
13341328 std::string msg = " Cannot find module " + spec + " (tried " + absPath + " )" ;
1335- isolate->ThrowException (v8::Exception::Error (tns::ToV8String (isolate, msg)));
1336- return v8::MaybeLocal<v8::Module>();
1329+ if (RuntimeConfig.IsDebug ) {
1330+ Log (@" Debug mode - Optional module placeholder creation failed: %s " , msg.c_str ());
1331+ return v8::MaybeLocal<v8::Module>();
1332+ } else {
1333+ isolate->ThrowException (v8::Exception::Error (tns::ToV8String (isolate, msg)));
1334+ return v8::MaybeLocal<v8::Module>();
1335+ }
13371336 }
13381337 } else {
13391338 // Placeholder file already exists, use it
0 commit comments