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-scriptsskips protobufjs’s postinstall, leaving an incomplete install for some setups.- Generated static modules (
pbjs/pbtsoutput) are not committed and not generated in CI → import fails. - A globally expected
pbjsbinary 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.
# 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-cliCache & 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.
- uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}Common errors
Cannot find modulefor generated protobuf code → runpbjs/pbtsin CI or commit the output.pbjs: command not found→ installprotobufjs-cli(or usenpx 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-scriptssilently skip its postinstall. - Commit or generate pbjs/pbts output in CI so imports resolve.