i want generate a proto file for reactjs
this is the commands I tested:
protoc --js_out=import_style=commonjs,binary:. --grpc-web_out=import_style=commonjs,mode=grpcwebtext:. *.proto
protoc -I=. ./data.proto --js_out=import_style=commonjs,binary:. --grpc-web_out=import_style=commonjs,mode=grpcwebtext:.
and I get below error:
'protoc-gen-js' is not recognized as an internal or external command,
operable program or batch file.
--js_out: protoc-gen-js: Plugin failed with status code 1.
and I downloaded these packages in c:/ drive and added them to system variable:
protobuf-javascript-3.21.2-win64
protoc-27.1-win64
protoc-gen-grpc-web-1.5.0-windows-x86_64.exe
what is the problem? and how to fix it?
also check these links too
https://github.com/protocolbuffers/protobuf-javascript/issues/127
https://github.com/protocolbuffers/protobuf-javascript/pull/208
2
Answers
i followed below instruction and removed all versions fromfolders and name of packages and 2 js files generated https://github.com/grpc/grpc-web/issues/767#issuecomment-609438604
It’s confusing and the repo’s
protobuf-javascript
README
is unclear.When you run
protoc --js_out=
, the--js_out
refers to a separate binary (plugin, in this case calledprotoc-gen-js
) that must either be in the path or specified using the--plugin=
flag.The plugin name (e.g.
protoc-gen-js
) follows a pattern in which theprotoc-gen
prefix is removed and_out
and_opt
may be added to the revised name to form theprotoc
flags (i.e.--js_out
).Corrollary: when you add
--js_out
toprotoc
,protoc
looks (absent a--plugin=
flag) in the path for a binary calledprotoc-gen-js
to invoke.You can download the latest release here and I recommend putting the plugin in your path.
Then try the
protoc
command again.