dagger/dagger · error

existing go.mod path %q does not match the module's name %q

Error message

existing go.mod path %q does not match the module's name %q

What it means

Raised during module init (moduleConfig.IsInit) when an existing go.mod is found but its module path does not match the expected dagger/<kebab-module-name>. Guards against generating into a directory already belonging to a differently named Go module.

Source

Thrown at cmd/codegen/generator/go/generate_module.go:210

	moduleConfig := g.Config.ModuleConfig

	var needsRegen bool

	var daggerModPath string
	var goMod *modfile.File

	modname := fmt.Sprintf("dagger/%s", strcase.ToKebab(moduleConfig.ModuleName))
	// check for a go.mod already for the dagger module
	if content, err := os.ReadFile(filepath.Join(g.Config.OutputDir, moduleConfig.ModuleSourcePath, "go.mod")); err == nil {
		daggerModPath = moduleConfig.ModuleSourcePath

		goMod, err = modfile.ParseLax("go.mod", content, nil)
		if err != nil {
			return nil, false, fmt.Errorf("parse go.mod: %w", err)
		}

		if moduleConfig.IsInit && goMod.Module.Mod.Path != modname {
			return nil, false, fmt.Errorf("existing go.mod path %q does not match the module's name %q", goMod.Module.Mod.Path, modname)
		}
	}

	// could not find a go.mod, so we can init a basic one
	if goMod == nil {
		daggerModPath = moduleConfig.ModuleSourcePath
		goMod = new(modfile.File)

		goMod.AddModuleStmt(modname)
		goMod.AddGoStmt(goVersion)

		needsRegen = true
	}

	// sanity check the parsed go version
	//
	// if this fails, then the go.mod version is too high! and in that case, we
	// won't be able to load the resulting package

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Align the go.mod module directive with the module name in dagger.json
  2. Remove the stale go.mod if it belongs to an old/different module
  3. Rename the Dagger module to match the existing go.mod path
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at cmd/codegen/generator/go/generate_module.go:210 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/4ea4098f2c6105f2. Report an issue: GitHub.