Hello, I faced the problem when generating pb.js.

Environments

  • go version go1.12.8 darwin/amd64
  • github.com/twitchtv/twirp v5.9.0+incompatible
  • libprotoc 3.9.1

Problem

In my project, there is protobuf/ directory that contains several schema files (api.proto).
I try to generate js file as follows:

protoc --proto_path protobuf/ --twirp_typescript_out=library=pbjs:./protobuf api.proto && \
        npx pbjs -t static-module -w es6 -o protobuf/api.pb.js api.proto && \
        npx pbts --no-comments -o protobuf/api.pb.d.ts protobuf/api.pb.js
Usage: pbjs [options] <schema_path>

Options:
  -V, --version        output the version number
  --es5 <js_path>      Generate ES5 JavaScript code
  --es6 <js_path>      Generate ES6 JavaScript code
  --ts <ts_path>       Generate TypeScript code
  --decode <msg_type>  Decode standard input to JSON
  --encode <msg_type>  Encode standard input to JSON
  -h, --help           output usage information

It failed.

Solve

Use protobufjs instead of pbjs

$ npm i protobufjs

There is two libraries, protobufjs and pbjs.
pbjs is wrong but it can be accepted because it is the same command pbjs.

Ref