Repository: denoland/deno
File: runtime/js/99_main.js (JavaScript)

Code before:
      5: hasNodeModulesDir,
      6: argv0,
      7: shouldDisableDeprecatedApiWarning,
      8: shouldUseVerboseDeprecatedApiWarning,
      9: future,
      10: mode,
      11: servePort,
    } = runtimeOptions;

    if (mode === executionModes.run || mode === executionModes.serve) {
      let serve = undefined;
      core.addMainModuleHandler((main) => {
        if (ObjectHasOwn(main, "default")) {
          try {
            serve = registerDeclarativeServer(main.default);
          } catch (e) {
            if (mode === executionModes.serve) {
              throw e;
            }
          }
        }

        if (mode === executionModes.serve && !serve) {
          console.error(
            `%cerror: %cdeno serve requires %cexport default { fetch }%c in the main module, did you mean to run \"deno run\"?`,
            "color: yellow;",
            "color: inherit;",
            "font-weight: bold;",
            "font-weight: normal;",
          );
          return;
        }

        if (serve) {
          if (mode === executionModes.run) {
            console.error(
              `%cwarning: %cDetected %cexport default { fetch }%c, did you mean to run \"deno serve\"?`,
              "color: yellow;",
              "color: inherit;",
              "font-weight: bold;",
              "font-weight: normal;",
            );
          }
          if (mode === executionModes.serve) {
            serve({ servePort });
          }
        }
      });
    }

    // TODO(iuioiua): remove in Deno v2. This allows us to dynamically delete

Review comment (suggestion):
```suggestion
            `%cerror: %c\"deno serve\" requires %cexport default { fetch }%c in the main module, did you mean to run \"deno run\"?`,
```

Code after:
      5: hasNodeModulesDir,
      6: argv0,
      7: shouldDisableDeprecatedApiWarning,
      8: shouldUseVerboseDeprecatedApiWarning,
      9: future,
      10: mode,
      11: servePort,
      12: serveHost,
    } = runtimeOptions;

    if (mode === executionModes.run || mode === executionModes.serve) {
      let serve = undefined;
      core.addMainModuleHandler((main) => {
        if (ObjectHasOwn(main, "default")) {
          try {
            serve = registerDeclarativeServer(main.default);
          } catch (e) {
            if (mode === executionModes.serve) {
              throw e;
            }
          }
        }

        if (mode === executionModes.serve && !serve) {
          console.error(
            `%cerror: %cdeno serve requires %cexport default { fetch }%c in the main module, did you mean to run \"deno run\"?`,
            "color: yellow;",
            "color: inherit;",
            "font-weight: bold;",
            "font-weight: normal;",
          );
          return;
        }

        if (serve) {
          if (mode === executionModes.run) {
            console.error(
              `%cwarning: %cDetected %cexport default { fetch }%c, did you mean to run \"deno serve\"?`,
              "color: yellow;",
              "color: inherit;",
              "font-weight: bold;",
              "font-weight: normal;",
            );
          }
          if (mode === executionModes.serve) {
            serve({ servePort, serveHost });
          }
        }
      });
    }