protoc-gen-js: program not found or is not executable
Asked Answered
R

6

27

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.

Rembrandt answered 10/6, 2022 at 9:29 Comment(8)
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. protoc does match e.g. --go_out to protoc-gen-go for external plugins but, it should not need to do this for JavaScript.Hypochondriac
@Hypochondriac yes, its a recent version, I have this installed libprotoc 3.21.1Rembrandt
@Hypochondriac do you know a workaround for this?Rembrandt
Interesting..... See: Issue #10114Hypochondriac
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?)Hypochondriac
Found this too JavaScript support (May 2022). Was trying to understand the change from 3.20 to [4].21Hypochondriac
I previously had libprotoc 3.17.1 and it caused the same issueRembrandt
@Hypochondriac this issue exists only on Ubuntu - my coworkers who are using windows report no issuesRembrandt
B
31

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).

Bossism answered 6/7, 2022 at 20:46 Comment(3)
indeed, I had the same issue, downgrading solved itTacitus
How do I downgrade?Wadding
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.Carvel
T
26

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

  npm install -g protoc-gen-js
Tiu answered 11/2, 2023 at 18:48 Comment(0)
C
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
Chiliad answered 28/9, 2022 at 13:49 Comment(0)
E
2

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
Efface answered 24/7, 2023 at 12:43 Comment(0)
A
0

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

Aneurysm answered 2/7, 2023 at 13:52 Comment(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 ReviewShinto
D
0

There has been a lot of discussion on this error in the following issue:

Generate js file from proto file with protoc v21.1 #127

If any of you are open to using a different package for generating static code then you can use the following.

protobufjs-cli

Command line interface (CLI) for protobuf.js.

This can be used to translate between file formats and to generate static code as well as TypeScript definitions.

Installation:

npm i protobufjs-cli

Usage:

$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto

I started using this package after I got the protoc-gen-js related error when using the protoc compiler for windows. I didn't find any solution mentioned in the issue linked above (as of June 2024) appealing, and I didn't want to install protoc-gen-js globally.

Daltondaltonism answered 11/6 at 20:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.