go
build_error
ai_generated
true
./main.go:5:2: imported and not used: "fmt"
ID: go/imported-and-not-used
80%Fix Rate
95%Confidence
0Evidence
2024-01-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.x | active | — | — | — |
Root Cause
An import is declared but no identifier from that package is referenced in the file. Go treats unused imports as a compile error.
generic中文
声明了导入,但文件中未引用该包的任何标识符。Go 将未使用的导入视为编译错误。
Workarounds
-
98% success
// delete the import line, or run: goimports -w ./... # or: gofmt -w main.go
-
90% success
import _ "net/http/pprof"
Dead Ends
Common approaches that don't work:
-
100% fail
linters respect it but the compiler still errors
-
80% fail
compiles but is dead code and often flagged by vet
-
100% fail
does not disable unused-import errors