Imported and Not Used

"fmt" imported and not used

Quick Answer

You imported a package but never reference it in your code. Remove the unused import or use a blank identifier if you need the side effects.

Why This Happens

Go treats unused imports as a compile error, not a warning. This keeps code clean but can be annoying during development. You can use the blank identifier _ to import a package purely for its init() side effects.

The Problem

package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Println("hello")
    // os is never used
}

The Fix

package main

import "fmt"

func main() {
    fmt.Println("hello")
}

Step-by-Step Fix

  1. 1

    Identify the unused import

    The compiler error names the exact package that is imported but not used.

  2. 2

    Decide if it is needed

    If the import is not needed, remove it. If it is needed for side effects, prefix with a blank identifier.

  3. 3

    Use goimports or IDE tooling

    Run goimports to automatically add and remove imports as needed.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free