Update 08/04/2022
After go 1.17. The go command now understands //go:build
lines and prefers them over // +build
lines. The new syntax uses boolean expressions, just like Go, and should be less error-prone. Here are some more details
// go:build (darwin && cgo) || linux// +build darwin,cgo linux
My issue was that I had a stray import "C"
in my code and I was compiling with CGO_ENABLED=0
. This problem was hard to find because IntelliJ collapses all the imports into one statement.
try to remove folder x in go/src/golang.org/
In my case I just by an accident replaced original code by test file, it was containing the following comments:
//go:build unittest// +build unittest
I fixed the issue by simply doing Invalidate Caches under File Tab.
If you have a dependency requiring cgo (which includes x/net by default), you will get this error if your system does not have a C compiler. Can be easily fixed by installing gcc.
This error seems to present itself rather ambiguously.
In my case, my project uses CGO, and this error manifests when CGO_ENABLED=0
in the environment, which is solved by unsetting this env var, or setting CGO_ENABLED=1
In my case it appears the go get failed and the folder referenced in GOPATH was empty. Check your library folder which is complaining here.
In my case, after trying the go clean -modcache
solution, I also had to restart Goland before it stopped complaining about the build constraints.
"build constraints exclude all Go files in go/src/golang.org/x/net/routego"In Intellij :
If you get error build constraints exclude all Go files in ...
with go get
command, please specify the path as follows
Error:
$ go get {HOST}/platform/be-photo
Success:
$ go get {HOST}/platform/be-photo/external/client