cannot refer to unexported name Go Origin: Application & API Last updated 4 Nov 2026

Go: cannot refer to unexported name pkg.helper (undefined: pkg.helper)

You used a lowercase (unexported) identifier from another package; only capitalised names are visible outside their package.

Exact message you may see cannot refer to unexported namecannot refer to unexported name pkg.helpercannot refer to unexported field or methodunexported field or methodname not exported by package
Seen on: Go

Meaning

Rename the identifier to start with an uppercase letter (if you own the package), or use the package's public API. Struct fields follow the same rule: lowercase fields are skipped by encoding/json and are not accessible externally.

Common causes

  • Function/type/field starts with a lowercase letter
  • Accessing internal fields of a dependency
  • Using a name from another package's internal/ directory
  • Typo in capitalisation
  • JSON struct fields lowercase so they never serialise

⚡ Quick fix

  1. Export it: helper → Helper
  2. Use the exported API of the dependency
  3. Place code in the same package if it must stay private

Detailed fix by platform

Go

  1. Fields must be exported for JSON: Name string json:"name"``

How to diagnose

  1. Name — Uppercase first letter?
  2. Package — Same or other?
  3. Field — Used by json/reflect?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

assignment mismatch: 1 variable but f returns 2 values — Go: assignment mismatch: 1 variable but os.Open returns 2 values (Go)assignment mismatch: …cannot assign to struct field m[k].f in map — Go: cannot assign to struct field users["bob"].Age in map (Go)cannot assign to stru…cannot use x as type in assignment/argument — Go: cannot use "5" (untyped string constant) as int value in argument to f (Go)cannot use x as type …function main is undeclared in the main package — Go: runtime.main_main·f: function main is undeclared in the main package (Go)function main is unde…import cycle not allowed — Go: package app/models imports app/utils imports app/models: import cycle not allowed (Go)import cycle not allo…json: cannot unmarshal string into Go struct field — Go: json: cannot unmarshal string into Go struct field User.age of type int (Go)json: cannot unmarsha…undefined: x — Go: ./main.go:12:2: undefined: handler (Go)undefined: xcannot re…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.