Reputation: 1383
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.
Upvotes: 34
Views: 23098
Reputation: 4131
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.
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.
Upvotes: 0
Reputation: 577
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
Upvotes: 5
Reputation: 1
Can downgrade to @3 versions Please refer https://github.com/grpc/grpc-web/issues/704#issuecomment-1215965557
Upvotes: 0
Reputation: 449
run this command this command will globally install protoc-gen-js
npm install -g protoc-gen-js
Upvotes: 34
Reputation: 1469
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
Upvotes: 15
Reputation: 24154
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
).
For now, recommend downgrading to version 20.1
(libprotoc 3.20.1
).
Upvotes: 32