Go on Vercel error
Could not find an exported function in "api/index.go"
"Could not find an exported function in "api/index.go"" is a build error from Vercel's Go runtime (@vercel/go). It builds every .go file under api/ whose name does not end in _test.go as its own function, and it fails a file that has no exported top-level function with exactly two parameters, http.ResponseWriter and *http.Request, and no receiver. A helper package placed under api/, a handler spelled with a lower-case first letter, or a method on a struct all trigger it. Name the function with a capital letter, give it the (w http.ResponseWriter, r *http.Request) signature, and move code that is not a handler, such as database helpers, out of api/ into a folder like pkg/. Then redeploy.
Why does a helper file under api/ fail the build?
In the Vercel CLI source (fs-detectors, detect-builders.ts) the Go builder is attached to the pattern api/**/!(*_test).go, so every Go file below api/ is treated as a function entry point, including api/internal/db/db.go. The build then runs a small Go analyzer (analyze.go) on that file. It walks the top-level functions and takes the first one that is exported, has no receiver, has two parameters and has http.ResponseWriter and *http.Request in its parameter text. A file with no such function ends in the error above. A write-up from 2026-02-07 (jhartman.pl) hit this exact message after moving a database package to api/internal/db/db.go, and fixed it by moving the package to pkg/db/db.go and importing it from api/.
api/index.go package handler, exported Handler
api/users.go package handler, exported Handler
pkg/db/db.go helpers, outside api/
go.mod at the project rootWhat does "Please change package main to package handler" mean?
The same build step (packages/go/src/index.ts) throws the error "Please change package main to package handler" when a go.mod file is found and the function file declares package main. Files in api/ are not programs: they are compiled by Vercel into a function, so they use a package name other than main. The Vercel docs show package handler with an exported Handler.
package handler
import (
"fmt"
"net/http"
)
func Handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "ok")
}What if my app is one Go server with main.go, not files in api/?
Vercel's Go runtime docs (Beta) describe a second mode: a root go.mod plus main.go, cmd/api/main.go or cmd/server/main.go, a server that listens on the PORT environment variable, and the framework preset set to go. In that mode the build skips the api/ analysis (packages/go/src/index.ts takes the standalone branch first), so a server keeps package main and has no Handler function. If neither main.go nor the other two files exist, the build fails with "No Go entrypoint found. Expected one of: main.go, cmd/api/main.go, cmd/server/main.go".
{
"framework": "go"
}Checklist
How to fix it, then check the fix
- 01List every Go file Vercel will treat as a function. Each one must pass the next steps, or move out of api/:
find api -name "*.go" -not -name "*_test.go" - 02In each remaining file, check the package line (package handler, not package main) and that one top-level function starts with a capital letter and has the signature func Name(w http.ResponseWriter, r *http.Request), with no receiver.
- 03Move anything that is not a handler, such as database, auth or config helpers, to a folder outside api/, for example pkg/, and import it with the module path from go.mod.
- 04Keep go.mod at the project root: the Vercel docs say the runtime reads the Go version from its go directive and detects the file there, and that go.sum should be committed.
- 05Redeploy, read the build log for the file named in the error, and open the route (for api/users.go, /api/users): the build passes and the route answers.
Related
Related guides
Sources
Official docs behind this checklist
- Vercel, Using the Go Runtime with Vercel Functions
- @vercel/go, go-helpers.ts (the error text)
- @vercel/go, analyze.go (what counts as a handler)
- @vercel/go, index.ts (package main check, standalone mode)
- @vercel/go, entrypoint.ts (standalone entrypoints)
- Vercel CLI, fs-detectors detect-builders.ts (api/**/!(*_test).go)
- Jarek Hartman, Vercel functions with Go (2026-02-07)
Browse all launch guides · Read resources · How to make and check your next change
FAQ
FAQ for builders before launch
Can one file hold several handlers?
Not usefully. The analyzer prints the first exported function that matches the handler signature and stops, and the Vercel docs say each file that exports an http.HandlerFunc becomes a separate function. Use one file per route.
Does the function have to be called Handler?
No. The Vercel docs say the name can be any exported Go identifier, as long as it matches the http.HandlerFunc signature.
Does a _test.go file in api/ cause this error?
Not by itself. The builder pattern is api/**/!(*_test).go, so files whose names end in _test.go are not picked up as functions.