go-task/task · error

task: Taskfiles versions should match. First is "%s" but sec

Error message

task: Taskfiles versions should match. First is "%s" but second is "%s"

What it means

Taskfile.Merge merges an included Taskfile into the parent and requires both to declare the same schema version. If t1.Version and t2.Version differ, merging could mix incompatible semantics, so the merge is rejected with both versions in the message.

Source

Thrown at taskfile/ast/taskfile.go:43

	Output       Output
	Method       string
	Includes     *Includes
	Set          []string
	Shopt        []string
	Vars         *Vars
	Env          *Vars
	Tasks        *Tasks
	Silent       bool
	Dotenv       []string
	Run          string
	Interval     time.Duration
	UseGitignore *bool
}

// Merge merges the second Taskfile into the first
func (t1 *Taskfile) Merge(t2 *Taskfile, include *Include) error {
	if !t1.Version.Equal(t2.Version) {
		return fmt.Errorf(`task: Taskfiles versions should match. First is "%s" but second is "%s"`, t1.Version, t2.Version)
	}
	if len(t2.Dotenv) > 0 {
		return ErrIncludedTaskfilesCantHaveDotenvs
	}
	if t2.Output.IsSet() {
		t1.Output = t2.Output
	}
	if t1.Includes == nil {
		t1.Includes = NewIncludes()
	}
	if t1.Vars == nil {
		t1.Vars = NewVars()
	}
	if t1.Env == nil {
		t1.Env = NewVars()
	}
	if t1.Tasks == nil {
		t1.Tasks = NewTasks()

View on GitHub (pinned to 385e5ad92a)

Solutions

  1. Set the same `version:` in the included Taskfile as in the including one
  2. Update the included Taskfile's syntax to match the main file's version
  3. Inline or copy the tasks locally if you cannot modify the included file
  4. Consolidate version numbers across all Taskfiles in the repo

Example fix

# included Taskfile before
version: '2'

# after
version: '3'
Defensive patterns

Strategy: validation

Validate before calling

main, err := os.ReadFile("Taskfile.yml")
inc, err2 := os.ReadFile("included.yml")
// compare the version: fields (e.g. with gopkg.in/yaml.v3) before running task
var mv, iv struct{ Version string `yaml:"version"` }
_ = yaml.Unmarshal(main, &mv)
_ = yaml.Unmarshal(inc, &iv)
if mv.Version != iv.Version { /* fix versions first */ }

Type guard

func versionsMatch(a, b Taskfile) bool {
    return a.Version.Equal(b.Version)
}

Try / catch

if err := t1.Merge(t2, include); err != nil {
    var mismatch bool = strings.Contains(err.Error(), "versions should match")
    if mismatch {
        // prompt user to align versions, or load included file standalone
    }
    return err
}

Prevention

When it happens

Trigger: An `includes:` referenced Taskfile declares a different `version:` than the including Taskfile (e.g. main file uses `version: '3'`, included file uses `version: '2'`).

Common situations: Upgrading a project's main Taskfile to version 3 while included Taskfiles still say 2; vendoring Taskfiles from other repos pinned to older versions; forgetting to bump version in shared includes.

Related errors


AI-assisted analysis of go-task/task@385e5ad92a (2026-09-05). Data as JSON: /api/errors/2adb5bfb48aca2f7. Report an issue: GitHub.