Skip to content
Latchkey

How to Generate Protobuf/ts-proto Code in CI

ts-proto is a protoc plugin, so CI needs the protoc compiler on PATH plus the plugin wired up before any TypeScript is generated.

Generating gRPC/Protobuf TypeScript means two pieces: the protoc binary (a system tool) and the ts-proto npm plugin. Missing the compiler is the most common CI failure.

Why it fails in CI

  • protoc is not installed on the runner → protoc: command not found.
  • The ts-proto plugin path is wrong, so protoc cannot find it.
  • A protoc/plugin version skew produces invalid or empty output.

Install and run it reliably

Install protoc, install ts-proto, then invoke protoc with the plugin path pointed at the local binary. Pin the protoc version for reproducible output.

Terminal
# Debian/Ubuntu
apt-get update && apt-get install -y protobuf-compiler
# (or download a pinned protoc release for an exact version)

npm install ts-proto

protoc \
  --plugin=./node_modules/.bin/protoc-gen-ts_proto \
  --ts_proto_out=./src/generated \
  ./proto/service.proto

Cache & speed

Cache ~/.npm for the plugin. If you download a pinned protoc, cache it keyed on the version so it is not refetched.

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: ~/.npm
    key: npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}

Common errors

  • protoc: command not found → install protobuf-compiler or a pinned protoc.
  • --ts_proto_out: protoc-gen-ts_proto: Plugin failed → wrong --plugin path; point at node_modules/.bin.
  • Empty/partial output → protoc and ts-proto version skew; pin both.

Key takeaways

  • CI needs both the protoc compiler and the ts-proto npm plugin.
  • Point --plugin at the local protoc-gen-ts_proto binary.
  • Pin protoc for reproducible generated code.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →