go build_error ai_generated true

pattern embed.go: no matching files found

ID: go/embed-directive-file-not-found

Also available as: JSON · Markdown · 中文
92%Fix Rate
86%Confidence
1Evidence
2023-08-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Go 1.16 active
Go 1.17 active
Go 1.18 active
Go 1.19 active
Go 1.20 active
Go 1.21 active
Go 1.22 active

Root Cause

The //go:embed directive specifies a file or pattern that does not exist relative to the source file's directory, or the file is excluded by .gitignore or build constraints.

generic

中文

//go:embed 指令指定的文件或模式相对于源文件目录不存在,或者该文件被 .gitignore 或构建约束排除。

Official Documentation

https://pkg.go.dev/embed

Workarounds

  1. 95% success Verify the file exists relative to the source file; use a glob pattern like "static/*" to embed a directory
    Verify the file exists relative to the source file; use a glob pattern like "static/*" to embed a directory
  2. 85% success If the file is generated, ensure it is generated before the build (e.g., using go generate)
    If the file is generated, ensure it is generated before the build (e.g., using go generate)

中文步骤

  1. 确认文件相对于源文件存在;使用通配符如 "static/*" 来嵌入目录
  2. 如果文件是生成的,确保在构建前生成(例如,使用 go generate)

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Go embed only supports relative paths (to the source file's directory); absolute paths are not allowed.

  2. 50% fail

    Gitignore does not affect Go's embed; the file must exist on disk at build time.