{"record":{"id":"468719eb7cb23cea","repo":"pulumi/pulumi","slug":"no-go-mod-file-found-v","errorCode":null,"errorMessage":"no go.mod file found: %v","messagePattern":"no go\\.mod file found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdk/go/pulumi-language-go/main.go","lineNumber":758,"sourceCode":"\t//\t\tGoMod    string // path to go.mod file\n\t//\t}\n\t//\n\t// See 'go help list' for the full definition.\n\tcmd := exec.Command(gobin, \"list\", \"-m\", \"-f\", \"{{.GoMod}}\")\n\t// Disable GOWORK, we only want the one module found in this (or a parent) directory. Workspaces being\n\t// enabled will cause \"list -m\" to list every module in the workspace.\n\tcmd.Env = append(os.Environ(), \"GOWORK=off\")\n\tcmd.Dir = programDir\n\tcmd.Stderr = os.Stderr\n\tout, err := cmd.Output()\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"go list -m: %w\", err)\n\t}\n\tout = bytes.TrimSpace(out)\n\tif len(out) == 0 {\n\t\t// The 'go list' command above will exit successfully\n\t\t// and return no output if the program is not in a Go module.\n\t\treturn \"\", nil, fmt.Errorf(\"no go.mod file found: %v\", programDir)\n\t}\n\n\tmodPath := string(out)\n\tbody, err := os.ReadFile(modPath)\n\tif err != nil {\n\t\treturn \"\", nil, err\n\t}\n\n\tf, err := modfile.Parse(modPath, body, nil)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"parse: %w\", err)\n\t}\n\n\treturn filepath.Dir(modPath), f, nil\n}\n\n// GetRequiredPackages computes the complete set of anticipated packages required by a program.\n// We're lenient here as this relies on the `go list` command and the use of modules.","sourceCodeStart":740,"sourceCodeEnd":776,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/pulumi-language-go/main.go#L740-L776","documentation":"`go list -m -f {{.GoMod}}` can exit 0 while printing nothing when the program is not in a Go module. loadGomod detects the empty output and raises this error naming the program directory. Like the go list -m error, GetRequiredPackages catches it upstream, logs it, and continues with no required packages.","triggerScenarios":"GetRequiredPackages -> loadGomod: `go list -m` succeeds but prints no GoMod path because programDir (req.Info.ProgramDirectory) is outside any module.","commonSituations":"Running a Pulumi Go program directory that never got `go mod init`; pointing main at the wrong folder via `main:` in Pulumi.yaml; CI checkout that excludes go.mod; GOPATH-mode projects migrated from older tooling.","solutions":["Run `go mod init github.com/you/myprogram` in the program directory (the one named in the error).","Verify Pulumi.yaml's `main:` points at the directory containing go.mod (or a subdir of it).","Ensure go.mod is committed/copied in CI and present in the working directory used by `pulumi up`.","Run `go list -m -f {{.GoMod}}` in that directory to confirm a path is printed before deploying."],"exampleFix":"// before: program dir without go.mod\n$ cd myprogram && pulumi up\n// after\ncd myprogram\ngo mod init example.com/myprogram\ngo mod tidy\npulumi up","handlingStrategy":"validation","validationCode":"// shell: ensure the deploy dir resolves to a go.mod\ntest -f go.mod || { echo \"run go mod init in $(pwd)\"; exit 1; }","typeGuard":null,"tryCatchPattern":"// empty output from `go list -m -f {{.GoMod}}` means not-in-module; treat as setup error\nif len(bytes.TrimSpace(out)) == 0 {\n    return fmt.Errorf(\"no go.mod file found: %v — run `go mod init` in the program dir\", programDir)\n}","preventionTips":["Commit go.mod (and go.sum) to version control so CI checkouts include them.","Verify the `main:` field in Pulumi.yaml points into the Go module.","Run `pulumi up` from the module root or a subdirectory of it."],"tags":["go","go-mod","language-host","project-setup"],"backgroundTag":"go-mod-not-found","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}