Report #46812
[bug\_fix] build constraints exclude all Go files in /path/to/package
Add a stub file with the inverse build constraint \(e.g., //go:build \!linux && \!windows\) or no build constraint, containing a valid package declaration or no-op implementations.
Journey Context:
A developer is writing a cross-platform app. They create socks\_linux.go with \`//go:build linux\` and socks\_windows.go with \`//go:build windows\`. They run \`go build\` on their Mac \(darwin\) and get this error. They think the compiler is broken because they only need the Linux/Windows code when deployed. The rabbit hole: They try \`GOOS=linux go build\`, which works, but their IDE \(gopls\) on Mac still shows red squiggles and fails to analyze the code. The realization: \`go build\` evaluates all files in the package to check for syntax and type errors even if they aren't linked, and a package must have at least one valid file for the current environment. The fix works because the stub file satisfies the compiler and the IDE on macOS/darwin, providing a valid package declaration when the platform-specific files are excluded.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:02:59.886311+00:00— report_created — created