21

Trying to compile my protos - I need to compile them to use in my react app. But I get this error. I run the command as follows:

cd src/main/proto && protoc -I=. *.proto --js_out=import_style=commonjs:. --grpc-web_out=import_style=commonjs,mode=grpcwebtext:.

Where can I find protoc-gen-js? I didn't come across any repo for it.

Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
Asma Rahim Ali Jafri
  • 1,173
  • 2
  • 15
  • 22
  • I think that JavaScript code generation is now built-in to `protoc`. Are you running a recent version of `protoc`? What does `protoc --version` yield? See [releases](https://github.com/protocolbuffers/protobuf/releases). `protoc` does match e.g. `--go_out` to `protoc-gen-go` for **external** plugins but, it should not need to do this for JavaScript. – DazWilkin Jun 11 '22 at 03:19
  • @DazWilkin yes, its a recent version, I have this installed `libprotoc 3.21.1` – Asma Rahim Ali Jafri Jun 13 '22 at 13:49
  • @DazWilkin do you know a workaround for this? – Asma Rahim Ali Jafri Jun 13 '22 at 13:50
  • 1
    Interesting..... See: [Issue #10114](https://github.com/protocolbuffers/protobuf/issues/10114) – DazWilkin Jun 13 '22 at 15:41
  • I have `protoc` 3.19.4 and that includes `protoc-gen-js`. You could revert to that, or chop through versions to find where it 'broke" (perhaps try 21.0?) – DazWilkin Jun 13 '22 at 15:43
  • Found this too [JavaScript support (May 2022)](https://developers.google.com/protocol-buffers/docs/news/2022-05-06#javascript). Was trying to understand the change from 3.20 to [4].21 – DazWilkin Jun 13 '22 at 15:47
  • I previously had `libprotoc 3.17.1` and it caused the same issue – Asma Rahim Ali Jafri Jun 13 '22 at 19:19
  • @DazWilkin this issue exists only on Ubuntu - my coworkers who are using windows report no issues – Asma Rahim Ali Jafri Jun 13 '22 at 19:20

5 Answers5

29

As of July 2022, there is a known bug in protoc versions 21.1 and 21.2 (and libprotoc 3.21.1 and libprotoc 3.21.2).

See protobuf issue #10114.

For now, recommend downgrading to version 20.1 (libprotoc 3.20.1).

Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117
  • 1
    indeed, I had the same issue, downgrading solved it – user2267367 Jul 14 '22 at 14:43
  • How do I downgrade? – David G Mar 09 '23 at 17:47
  • 1
    Thanks for the link! One year later the issue still isn't fixed though. But for now, it looks that like somebody made the plugin available, so you can install it manually as described in the comments there, which might be a better solution than downgrading. – NotX Apr 19 '23 at 08:05
13

For Mac users using brew and the provided link by Christopher Peisert what worked for me was the suggested workaround:

$brew install protobuf@3

$brew link --overwrite protobuf@3
Alon Rosenfeld
  • 1,392
  • 13
  • 13
10

run this command this command will globally install protoc-gen-js

  npm install -g protoc-gen-js
0

Can downgrade to @3 versions Please refer https://github.com/grpc/grpc-web/issues/704#issuecomment-1215965557

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34629931) – sanitizedUser Jul 06 '23 at 10:20
0

You should install this package globally or in the project devDependencies.

NPM

npm install -g protoc-gen-js
// or
npm install protoc-gen-js --save-dev

YARN

yarn global add protoc-gen-js
// or
yarn add protoc-gen-js --dev
Роман
  • 479
  • 6
  • 7