Skip to content
Latchkey

protoc "Import X was not found or had errors" in CI

protoc reports this on the importing file when a dependency it pulls in either cannot be found on the import path or itself failed to compile. Fix the imported file (or its path) first; this error clears once the dependency parses.

What this error means

protoc prints "api/v1/user.proto:5:1: Import \"common/types.proto\" was not found or had errors." usually alongside a "File not found" or a parse error on the imported proto.

protoc
common/types.proto:3:8: Expected "required", "optional", or "repeated".
api/v1/user.proto:5:1: Import "common/types.proto" was not found or had errors.

Common causes

The imported file is not on the import path

A missing -I root means protoc cannot find the dependency, so it flags the importing file as having a bad import.

The imported file has its own compile error

When the dependency fails to parse, protoc cannot compile the importer either; the real error is on the imported file above this line.

How to fix it

Fix the dependency error first

  1. Read the error printed on the imported file above this message.
  2. Correct that syntax or path error.
  3. Re-run protoc; the "had errors" cascade clears once the import compiles.

Ensure the import root is on the path

If the imported file is fine, add the directory that makes its import path resolve with -I.

Terminal
protoc -I proto -I common --go_out=gen proto/api/v1/user.proto

How to prevent it

  • Compile leaf protos first so dependency errors surface directly.
  • Keep every import root on -I in both local and CI runs.
  • Use buf build which reports the underlying error with clearer location info.

Frequently asked questions

What causes ""was not found or had errors""?
A missing -I root means protoc cannot find the dependency, so it flags the importing file as having a bad import.
How do I fix "was not found or had errors"?
Fix the dependency error first

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card