protocolbuffers / protobuf-javascript

BSD 3-Clause "New" or "Revised" License
351 stars 67 forks source link

Can't make `protoc-gen-js` work on MacOS #183

Closed plvaldes closed 8 months ago

plvaldes commented 9 months ago

Hi all,

I don't know if I missed any installation docs, but I am trying to generate the javascript files for the helloworld example in grpc-web and I am having issues with protoc-gen-js. I think this needs to be manually installed now as protoc is not supporting javascript output anymore.

When I run :

protoc -I=. helloworld.proto \
  --js_out=import_style=commonjs:. \
  --grpc-web_out=import_style=commonjs,mode=grpcwebtext:.

I get the following error:

/usr/local/bin/protobuf-javascript/bin/protoc-gen-js: /usr/local/bin/protobuf-javascript/bin/protoc-gen-js: cannot execute binary file
--js_out: protoc-gen-js: Plugin failed with status code 126.

/usr/local/bin/protobuf-javascript is where I moved protobuf-javascript-3.21.2-linux-x86_64.zip after downloading it (also made sure that protoc-gen-js is executable with chmod).

As a test I tried to just execute protoc-gen-js and got the following error:

zsh: exec format error: /usr/local/bin/protobuf-javascript/bin/protoc-gen-js

In the readme file of this repo there are setup instructions but they didn't help me. They suggest downloading the Protocol Buffer source code and running tests on the js directory, but I think that directory is not part of Protocol Buffer anymore.

I'm running this on MacOS 14.2 (23C64)

I'd appreciate some help to get this installed 🙏🏼

dibenede commented 9 months ago

Are you on an Intel or Apple Silicon Mac?

plvaldes commented 9 months ago

Hi @dibenede , I am on an Apple M1.

I was suggested to globally install protoc-gen-js package (I can't see the message in this thread, I guess it's been deleted) which is on npm and that solved my problem in the short term (however I'd like to understand what the issue was and document it in grpc-web if it is a well-known issue that affects a large number of users).

Thanks

dibenede commented 9 months ago

You are using the 64-bit intel package. You should try protobuf-javascript-3.21.2-osx-aarch_64.tar.gz

plvaldes commented 8 months ago

Thank you @dibenede , I had the wrong version 🤦🏻‍♂️. Closing ticket

Alex-Li2018 commented 8 months ago

Hi @dibenede , I am on an Apple M1.

I was suggested to globally install protoc-gen-js package (I can't see the message in this thread, I guess it's been deleted) which is on npm and that solved my problem in the short term (however I'd like to understand what the issue was and document it in grpc-web if it is a well-known issue that affects a large number of users).

Thanks

Hi! @plvaldes. I am on apple M2. I encountered the same problem as you, but your solution didn't work.

Alex-Li2018 commented 8 months ago

My mistake, your solution work well.