Skip to content
Latchkey

How to Install protobufjs in CI Without postinstall Failures

protobufjs is pure JavaScript, so it has no native build - the CI snags are a blocked postinstall script and the pbjs/pbts code-generation step.

protobufjs is a pure-JS Protocol Buffers implementation, so there is no compiler or system library involved. CI issues come from --ignore-scripts blocking its postinstall, and from teams expecting pbjs/pbts generated files to exist without running the generation step in the pipeline.

Why it fails in CI

  • npm ci --ignore-scripts skips protobufjs’s postinstall, leaving an incomplete install for some setups.
  • Generated static modules (pbjs/pbts output) are not committed and not generated in CI → import fails.
  • A globally expected pbjs binary is missing because protobufjs-cli was not installed.

Install it reliably

Install normally so the postinstall runs, and either commit the generated pbjs/pbts output or run generation as an explicit CI step. There is no toolchain to add - it is pure JS.

Terminal
# pure JS - no compiler/system libs
npm ci

# if you use static generation, run it in CI (or commit the output):
npx pbjs -t static-module -w commonjs -o compiled.js *.proto
npx pbts -o compiled.d.ts compiled.js
# pbjs/pbts come from protobufjs-cli

Cache & speed

Cache ~/.npm keyed on the lockfile - there is nothing to compile. If you generate code in CI, cache the generated output keyed on the .proto file hashes so regeneration only runs on change.

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

Common errors

  • Cannot find module for generated protobuf code → run pbjs/pbts in CI or commit the output.
  • pbjs: command not found → install protobufjs-cli (or use npx pbjs).
  • Incomplete install with --ignore-scripts → allow protobufjs’s postinstall or pre-generate static modules.

Key takeaways

  • protobufjs is pure JS - no native build or system libraries.
  • Do not let --ignore-scripts silently skip its postinstall.
  • Commit or generate pbjs/pbts output in CI so imports resolve.

Related guides

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