Skip to content
Latchkey

Go "//go:embed: no matching files found" - Fix Embeds in CI

The //go:embed directive bakes files into the binary at build time. It fails when the pattern matches nothing - an asset that was not committed, a path outside the package directory, or a missing import "embed" - so the build cannot find what it was told to embed.

What this error means

A build fails with pattern <glob>: no matching files found, //go:embed only allowed in Go files that import "embed", or cannot embed directory ... contains no embeddable files. It often appears in CI where a generated or gitignored asset is absent.

go build output
./assets.go:8:12: pattern static/*: no matching files found
# or:
./assets.go:8:12: //go:embed only allowed in Go files that import "embed"

Common causes

The embedded asset is not present at build time

A file matched by the pattern was gitignored, generated by a step that did not run, or lives outside the package directory - so CI has nothing to embed.

Missing import "embed"

Using //go:embed requires importing the embed package (even as _ "embed" for a string/[]byte target); without it the directive is rejected.

Pattern reaching outside the package directory

//go:embed cannot match .. paths or files outside the directory of the Go file; such patterns find nothing.

How to fix it

Commit the asset and import embed

Ensure the file exists in the repo and the package imports embed.

Go
import _ "embed"

//go:embed static/index.html
var indexHTML string

Generate embedded assets before building

If assets are produced by a step, run it before go build so the files exist.

.github/workflows/ci.yml
npm run build           # produces ./static/*
go build ./...          # embed now finds the files

Keep embed patterns inside the package directory

  1. Move embedded assets under the package directory (no .. paths).
  2. Use all: prefix to include files the default rules skip (dotfiles, _-prefixed).
  3. Confirm the glob matches with ls before building.

How to prevent it

  • Commit embedded assets, or generate them before go build in CI.
  • Import embed in any file using //go:embed.
  • Keep embed patterns within the package directory.

Related guides

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