{"record":{"id":"4cbb08ba53fc043a","repo":"go-kratos/kratos","slug":"go-mod-don-t-exists-in-s","errorCode":null,"errorMessage":"🚫 go.mod don't exists in %s","messagePattern":"🚫 go\\.mod don't exists in (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kratos/internal/project/project.go","lineNumber":90,"sourceCode":"\tdone := make(chan error, 1)\n\tvar repoURL string\n\tif repo != \"\" {\n\t\trepoURL = repo\n\t} else {\n\t\trepoURL, err = selectRepo()\n\t\tif err != nil {\n\t\t\tfmt.Fprintf(os.Stderr, \"\\033[31mERROR: failed to select repo(%s)\\033[m\\n\", err.Error())\n\t\t\treturn\n\t\t}\n\t}\n\tgo func() {\n\t\tif !nomod {\n\t\t\tdone <- p.New(ctx, workingDir, repoURL, branch)\n\t\t\treturn\n\t\t}\n\t\tprojectRoot := getgomodProjectRoot(workingDir)\n\t\tif gomodIsNotExistIn(projectRoot) {\n\t\t\tdone <- fmt.Errorf(\"🚫 go.mod don't exists in %s\", projectRoot)\n\t\t\treturn\n\t\t}\n\n\t\tpackagePath, e := filepath.Rel(projectRoot, filepath.Join(workingDir, projectName))\n\t\tif e != nil {\n\t\t\tdone <- fmt.Errorf(\"🚫 failed to get relative path: %v\", e)\n\t\t\treturn\n\t\t}\n\t\tpackagePath = strings.ReplaceAll(packagePath, \"\\\\\", \"/\")\n\n\t\tmod, e := base.ModulePath(filepath.Join(projectRoot, \"go.mod\"))\n\t\tif e != nil {\n\t\t\tdone <- fmt.Errorf(\"🚫 failed to parse `go.mod`: %v\", e)\n\t\t\treturn\n\t\t}\n\t\t// Get the relative path for adding a project based on Go modules\n\t\tp.Path = filepath.Join(strings.TrimPrefix(workingDir, projectRoot+\"/\"), p.Name)\n\t\tdone <- p.Add(ctx, workingDir, repoURL, branch, mod, packagePath)","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/cmd/kratos/internal/project/project.go#L72-L108","documentation":"Kratos CLI error raised in no-module mode: when adding a subproject (kratos new <name> with nomod), the CLI walks up from the working directory to find a project root containing go.mod. If none exists, the new package cannot be given a module-relative import path, so creation aborts with this error.","triggerScenarios":"Running kratos new <name> in no-module mode from a directory where no ancestor directory contains go.mod — getgomodProjectRoot(workingDir) returns a root for which gomodIsNotExistIn is true.","commonSituations":"Running the CLI from $HOME or /tmp; forgetting go mod init in a fresh repo; scaffolding a sub-service before the parent module exists; wrong terminal cwd.","solutions":["cd into the intended parent project (the one with go.mod) and rerun the command","If no module exists yet: run go mod init <module-path> in the intended parent, then rerun with nomod","Or drop the nomod mode so the CLI scaffolds a standalone project with its own go.mod"],"exampleFix":"# before\n$ cd ~ && kratos new users --nomod\n# go.mod don't exists in /home/me\n\n# after\n$ mkdir shop && cd shop && go mod init github.com/me/shop\n$ kratos new users --nomod","handlingStrategy":"validation","validationCode":"// before shelling out to kratos new in no-module mode\nif _, err := os.Stat(\"go.mod\"); err != nil {\n    log.Fatal(\"no go.mod here: run `go mod init <path>` or drop the nomod mode\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always scaffold from the module root (the repo checkout)","Run go mod init before adding subprojects","Verify cwd with `git rev-parse --show-toplevel` before scaffolding"],"tags":["cli","go-modules","scaffolding","go"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}