{"record":{"id":"49b7d30b18cc8745","repo":"denoland/deno","slug":"no-main-module","errorCode":null,"errorMessage":"No main module.","messagePattern":"No main module\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/args/mod.rs","lineNumber":899,"sourceCode":"                resolver,\n                default_resolve,\n              )?\n            }\n          }\n          DenoSubcommand::Serve(run_flags) => self\n            .resolve_main_module_with_resolver_if_bare(\n              &run_flags.script,\n              resolver,\n              || {\n                resolve_url_or_path_normalized(\n                  &run_flags.script,\n                  self.initial_cwd(),\n                )\n                .map_err(|e| e.into())\n              },\n            )?,\n          _ => {\n            bail!(\"No main module.\")\n          }\n        })\n      })\n      .as_ref()\n      .map_err(|err| deno_core::anyhow::anyhow!(\"{}\", err))\n  }\n\n  pub fn resolve_main_module(&self) -> Result<&ModuleSpecifier, AnyError> {\n    self.resolve_main_module_with_resolver(None)\n  }\n\n  pub fn resolve_file_header_overrides(\n    &self,\n  ) -> HashMap<ModuleSpecifier, HashMap<String, String>> {\n    let maybe_main_specifier = self.resolve_main_module().ok();\n    let maybe_content_type = self.flags.ext.as_ref().and_then(|ext| {\n      let media_type = MediaType::from_filename(&format!(\"file.{}\", ext));\n      media_type.as_content_type()","sourceCodeStart":881,"sourceCodeEnd":917,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/args/mod.rs#L881-L917","documentation":"resolve_main_module_with_resolver maps the active subcommand (run, bench, compile, ...) to its entry module. For subcommands that have no main module - eval, repl, task, install, and others - the match falls into a bail with \"No main module.\" instead of returning a specifier.","triggerScenarios":"Calling flags.resolve_main_module() (directly or through an API that needs the entry specifier) when the parsed CLI flags correspond to a subcommand without a main module, e.g. deno eval or deno repl arguments.","commonSituations":"Embedders reusing deno CLI argument plumbing; code assuming every invocation has an entry file; subcommand flags parsed differently than expected.","solutions":["Check the active DenoSubcommand variant before asking for a main module","Use the subcommand-specific flags directly (e.g. run_flags.script) for non-run subcommands","Fix the CLI invocation so the intended subcommand is parsed"],"exampleFix":"// before\nlet main = flags.resolve_main_module()?; // deno eval flags -> No main module.\n\n// after\nif let DenoSubcommand::Run(_) = &flags.subcommand {\n  let main = flags.resolve_main_module()?;\n}","handlingStrategy":"validation","validationCode":"use deno_args::DenoSubcommand;\n\nfn has_main_module(flags: &Flags) -> bool {\n  matches!(\n    flags.subcommand,\n    DenoSubcommand::Run(_) | DenoSubcommand::Bench(_) | DenoSubcommand::Compile(_)\n  )\n}\n\nif !has_main_module(&flags) {\n  return Err(\"this subcommand has no main module\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Branch on the parsed subcommand before requesting the main module","For non-run subcommands, read the entry from the subcommand's own flags struct"],"tags":["cli-args","main-module","subcommand","embedder"],"backgroundTag":"missing-main-module","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}