pulumi/pulumi · warning
no go.mod file found: %v
Error message
no go.mod file found: %v
What it means
`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.
Source
Thrown at sdk/go/pulumi-language-go/main.go:758
// GoMod string // path to go.mod file
// }
//
// See 'go help list' for the full definition.
cmd := exec.Command(gobin, "list", "-m", "-f", "{{.GoMod}}")
// Disable GOWORK, we only want the one module found in this (or a parent) directory. Workspaces being
// enabled will cause "list -m" to list every module in the workspace.
cmd.Env = append(os.Environ(), "GOWORK=off")
cmd.Dir = programDir
cmd.Stderr = os.Stderr
out, err := cmd.Output()
if err != nil {
return "", nil, fmt.Errorf("go list -m: %w", err)
}
out = bytes.TrimSpace(out)
if len(out) == 0 {
// The 'go list' command above will exit successfully
// and return no output if the program is not in a Go module.
return "", nil, fmt.Errorf("no go.mod file found: %v", programDir)
}
modPath := string(out)
body, err := os.ReadFile(modPath)
if err != nil {
return "", nil, err
}
f, err := modfile.Parse(modPath, body, nil)
if err != nil {
return "", nil, fmt.Errorf("parse: %w", err)
}
return filepath.Dir(modPath), f, nil
}
// GetRequiredPackages computes the complete set of anticipated packages required by a program.
// We're lenient here as this relies on the `go list` command and the use of modules.View on GitHub (pinned to 793f7b2e16)
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.
Example fix
// before: program dir without go.mod $ cd myprogram && pulumi up // after cd myprogram go mod init example.com/myprogram go mod tidy pulumi up
Defensive patterns
Strategy: validation
Validate before calling
// shell: ensure the deploy dir resolves to a go.mod
test -f go.mod || { echo "run go mod init in $(pwd)"; exit 1; } Try / catch
// empty output from `go list -m -f {{.GoMod}}` means not-in-module; treat as setup error
if len(bytes.TrimSpace(out)) == 0 {
return fmt.Errorf("no go.mod file found: %v — run `go mod init` in the program dir", programDir)
} Prevention
- 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.
When it happens
Trigger: GetRequiredPackages -> loadGomod: `go list -m` succeeds but prints no GoMod path because programDir (req.Info.ProgramDirectory) is outside any module.
Common situations: 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.
Related errors
- go list -m: %w
- parse: %w
- language did not return handshake response, attaching via an
- illegal semver returned by language host: %s@%s: %w
- unrecognized plugin kind: %s
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/468719eb7cb23cea.
Report an issue: GitHub.