{"record":{"id":"ede9613a6ea50d4e","repo":"gohugoio/hugo","slug":"no-modules-loaded-need-at-least-the-main-module","errorCode":null,"errorMessage":"no modules loaded (need at least the main module)","messagePattern":"no modules loaded \\(need at least the main module\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"config/allconfig/allconfig.go","lineNumber":958,"sourceCode":"\t\tfor _, s := range allDecoderSetups {\n\t\t\tif getInitializer := s.getInitializer; getInitializer != nil {\n\t\t\t\tif err := getInitializer(langConfig).InitConfig(logger, nil, c.ConfiguredDimensions); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tc.configLangs[i] = ConfigLanguage{\n\t\t\tm:             c,\n\t\t\tconfig:        langConfig,\n\t\t\tbaseConfig:    c.LoadingInfo.BaseConfig,\n\t\t\tlanguage:      l,\n\t\t\tlanguageIndex: i,\n\t\t}\n\t}\n\n\tif len(c.Modules) == 0 {\n\t\treturn errors.New(\"no modules loaded (need at least the main module)\")\n\t}\n\n\t// Apply default project mounts.\n\tif err := modules.ApplyProjectConfigDefaults(logger.Logger(), c.Modules[0], c.configLangs...); err != nil {\n\t\treturn err\n\t}\n\n\t// We should consolidate this, but to get a full view of the mounts in e.g. \"hugo config\" we need to\n\t// transfer any default mounts added above to the config used to print the config.\n\tfor _, m := range c.Modules[0].Mounts() {\n\t\tvar found bool\n\t\tfor _, cm := range c.Base.Module.Mounts {\n\t\t\tif cm.Equal(m) {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif !found {","sourceCodeStart":940,"sourceCodeEnd":976,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/config/allconfig/allconfig.go#L940-L976","documentation":"After collecting modules, Hugo's config Init requires at least the main module. If c.Modules is empty, initialization aborts with this error. It typically means the working directory is not a valid Hugo project (no config file resolved and/or no go.mod/module graph) so module loading produced nothing.","triggerScenarios":"Running hugo from a directory with no resolvable config and no module information, or after module collection silently returned an empty set due to import failures.","commonSituations":"Wrong working directory (running from a subfolder); `hugo mod init` never run so there is no main module; broken module imports or a themesDir/content mount that prevents the main module from registering; CI running in the wrong checkout path.","solutions":["Run hugo from the project root that contains the config file (hugo.toml/yaml/json).","Run `hugo mod init github.com/me/site` to establish the main module.","Verify the `module` config block and theme/module paths resolve; check earlier log lines for module load warnings."],"exampleFix":"// before: run from a subfolder with no config\nhugo\n// after\nhugo mod init github.com/me/site\nhugo server   # from project root","handlingStrategy":"validation","validationCode":"// Before building, ensure a config file resolves in the working dir\nif _, err := os.Stat(filepath.Join(workDir, \"hugo.toml\")); err != nil {\n    return fmt.Errorf(\"no Hugo config in %s; run `hugo new site .` or `hugo mod init`\", workDir)\n}","typeGuard":null,"tryCatchPattern":"cfg, err := allconfig.LoadConfig(d)\nif err != nil {\n    if strings.Contains(err.Error(), \"no modules loaded\") {\n        // prompt user to scaffold/init the module, then retry\n    }\n    return err\n}","preventionTips":["Always run hugo from the directory containing hugo.toml.","Run `hugo mod init` once to establish the main module.","Verify `hugo config` lists the main module before building."],"tags":["config","hugo","module","go","cli"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}