go
compile_error
ai_generated
true
imported and not used
ID: go/imported-not-used
98%Fix Rate
95%Confidence
290Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Go requires all imports to be used. This is a compile error, not a warning.
genericWorkarounds
-
98% success Use goimports or gopls to auto-manage imports
Use goimports or gopls to auto-manage imports
Sources: https://pkg.go.dev/golang.org/x/tools/cmd/goimports
-
95% success Remove the unused import line
// Simply delete the unused import line. // Or use goimports to auto-manage imports: // go install golang.org/x/tools/cmd/goimports@latest // goimports -w . // For side-effect imports, use blank identifier: import _ "image/png"
Dead Ends
Common approaches that don't work:
-
Comment out the import
60% fail
Messy, easy to forget, and goimports will re-add it
-
Use blank identifier _ for every unused import
55% fail
Only correct for side-effect imports, not for temporarily unused ones
Error Chain
Leads to:
Preceded by:
Frequently confused with: