Skip to content
Latchkey

Go "errors parsing go.mod" - Fix a Malformed go.mod in CI

Go could not parse go.mod at all. An unknown directive, leftover merge-conflict markers, or invalid syntax makes the file unreadable, so every command fails before any build work begins.

What this error means

A go command fails immediately with errors parsing go.mod: and a line number describing the problem - an unexpected token, an unknown directive, or a conflict marker. Nothing builds because the module file itself is broken.

go output
go: errors parsing go.mod:
/app/go.mod:7: unknown directive: requrie
/app/go.mod:12: unexpected input: <<<<<<< HEAD

Common causes

Leftover merge-conflict markers

A bad merge left <<<<<<<, =======, or >>>>>>> markers in go.mod, which the parser cannot read.

An unknown or misspelled directive

A hand-edited typo (requrie for require, a stray keyword) is not a directive Go recognizes, so parsing stops.

Invalid syntax in a block

A malformed require/replace block - a missing version, an unclosed parenthesis - makes the line unparseable.

How to fix it

Resolve merge conflicts in go.mod

  1. Open go.mod at the reported line and remove every conflict marker.
  2. Keep the correct require/replace lines from both sides.
  3. Run go mod tidy so the file is reconciled and valid.

Let go mod edit rewrite the file cleanly

Using go mod edit writes directives in the exact format Go expects, fixing typos and formatting.

Terminal
go mod edit -fmt
go mod tidy

Validate go.mod in CI

.github/workflows/ci.yml
go mod edit -json > /dev/null   # nonzero exit if go.mod is unparseable

How to prevent it

  • Resolve merge conflicts in go.mod carefully and re-tidy afterward.
  • Edit go.mod with go mod edit, not by hand.
  • Add a parse check (go mod edit -json) to CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →