# Go: ./main.go:5:2: "os" imported and not used

**Code:** `imported and not used` · **Category:** Go · **Seen on:** Go

The file imports a package that no code in that file uses; Go treats this as a compile error, not a warning.

## Meaning

Remove the import, or use it. If you import only for side effects (database drivers, `image/png`), use the blank identifier `_`. Tools like `goimports` or `gopls` add and remove imports on save.

## Common causes

- Import left over after refactoring
- Debug code (fmt.Println) removed but import stays
- Package used only in commented-out code
- Driver needed for side effects only
- Name collision with a local variable

## Quick fix

1. Delete the unused import line
2. Use `goimports -w .` to fix automatically
3. For side effects write `import _ "github.com/lib/pq"`

## Detailed fix by platform

### Go

1. `go install golang.org/x/tools/cmd/goimports@latest && goimports -w .`

## How to diagnose

1. **Import** — Which package named?
2. **Use** — Referenced in this file?
3. **Side effect** — Blank import intended?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/go/imported-and-not-used)
