Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

golangci-lint fails in GitHub Actions with typecheck errors like can't load fmt

Errorcan't load fmt

Short answer

golangci-lint only supports Go versions up to the one it was compiled with. If your go.mod or setup-go uses a newer Go than your linter build, it fails to load even the standard library. Update the linter version in the action and install Go with setup-go before it.

  • Applies to golangci-lint 2, golangci-lint-action 9, actions/setup-go 6
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the Go version the linter was built with and compare it with the Go version your job installs.

    golangci-lint version
    go version
  2. 2Match what you see, then jump to its fix

    1. 1The failure started after you raised go.mod or setup-go to a newer Go, and the action still pins an old versionThe pinned golangci-lint was built with an older Go than the project usesFix
    2. 2The job has checkout and the lint action only; the runner's default Go is usedThere is no actions/setup-go step before the lint actionFix

What does the error look like?

  • can't load fmt
  • typecheck errors that stop all other golangci-lint reports
  • the same code lints fine locally with a newer golangci-lint

Cause 1 of 2

The pinned golangci-lint was built with an older Go than the project uses

1Check

The FAQ states that golangci-lint supports Go versions lower than or equal to the one used to compile it. Check the pinned version in the workflow.

grep -n "golangci\|version\|go-version" .github/workflows/*.yml

2Fix

Raise the version input to a release built with a Go at least as new as the project's, or use latest.

- uses: golangci/golangci-lint-action@v9
  with:
    version: latest

3Verify

Re-run the job; typecheck errors are gone.

golangci-lint run ./...

Confirmed by golangci-lint.run

Did this fix it?

Cause 2 of 2

There is no actions/setup-go step before the lint action

1Check

The action needs an explicit actions/setup-go step before it runs.

grep -n "setup-go" .github/workflows/*.yml

2Fix

Add setup-go with the Go version your module needs, ahead of the lint step.

- uses: actions/checkout@v6
- uses: actions/setup-go@v6
  with:
    go-version: stable
- uses: golangci/golangci-lint-action@v9
  with:
    version: latest

3Verify

The job logs the Go version you chose, and lint runs.

go version

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Pin a minor version such as v2.13 for repeatable runs, and raise it whenever you raise the Go version.
  • Run golangci-lint version in a CI step so the pair of versions is always in the log.
  • Read typecheck errors first; golangci-lint cannot produce other reports while they exist.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Servers

docker pull or push to ghcr.io fails with 'denied'

Error response from daemon: denied

ghcr.io refuses a pull or push when Docker is not logged in, when the token lacks the package scope, or when the workflow's GITHUB_TOKEN has no packages permission or no access to that package.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.