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.
./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.
import _ "embed"
//go:embed static/index.html
var indexHTML stringGenerate embedded assets before building
If assets are produced by a step, run it before go build so the files exist.
npm run build # produces ./static/*
go build ./... # embed now finds the filesKeep embed patterns inside the package directory
- Move embedded assets under the package directory (no
..paths). - Use
all:prefix to include files the default rules skip (dotfiles,_-prefixed). - Confirm the glob matches with
lsbefore building.
How to prevent it
- Commit embedded assets, or generate them before
go buildin CI. - Import
embedin any file using//go:embed. - Keep embed patterns within the package directory.