Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protoc-gen-js: program not found or is not executable #704

Closed
raymond-liao opened this issue Jan 13, 2020 · 5 comments
Closed

protoc-gen-js: program not found or is not executable #704

raymond-liao opened this issue Jan 13, 2020 · 5 comments

Comments

@raymond-liao
Copy link

I use grpc_tools to generate the code of proto files in python script, but I got errors after I installed protoc-gen-grpc-web and run the script. But the command protoc -I=. *.proto --js_out=import_style=commonjs:. is working without any errors in Terminal.

My python script

from grpc_tools import protoc

protoc.main((
    '',
    '-I.',
    '--python_out=./target/python',
    '--swift_out=./target/swift',
    '--js_out=import_style=commonjs:./target/js',
    './message_body.proto',
    './message_const.proto',
    './grpc_services/guardian.proto',
    './grpc_services/auth.proto'
))

protoc.main((
    '',
    '-I.',
    '--grpc_python_out=./target/python',
    '--swiftgrpc_out=Client=true,Server=false:./target/swift',
    '--grpc-web_out=import_style=commonjs,mode=grpcwebtext:./target/js',
    './grpc_services/guardian.proto',
    './grpc_services/auth.proto'
))

The errors of my script

protoc-gen-js: program not found or is not executable
--js_out: protoc-gen-js: Plugin failed with status code 1.

Warning: the grpc code file is generated after run the script

How can I fix this for my script? Or do I need install the generator protoc-gen-js? Please help.

@stanley-cheung
Copy link
Collaborator

Doesn't seem like this is a grpc-web issue, especially if protoc -I=. *.proto --js_out=import_style=commonjs:. runs fine from the command line. This seems like an issue with grpc_tools itself.

@hbak
Copy link

hbak commented Jun 3, 2022

@sfc-gh-shsharma
Copy link

If anyone is having this problem on macOS and got here from Google, a workaround that worked for me:

brew install protobuf@3
brew link --overwrite protobuf@3

protocolbuffers/protobuf-javascript#127 (comment)

PanagiotisPtr pushed a commit to PanagiotisPtr/hermes-messenger that referenced this issue Aug 22, 2022
As you are doing this you probably want to have a look at these:
https://github.com/grpc/grpc-web
grpc/grpc-web#704 (comment)
@yinzara
Copy link

yinzara commented Feb 8, 2023

I have created a npm package to help everyone.
https://www.npmjs.com/package/protoc-gen-js

You can now npm i protoc-gen-js inside a package.json directory to make the '--js_out' work in "scripts" in the package.json (i.e. if one of your package.json scripts calls 'protoc --js_out') and will allow you to specify the version of protoc-gen-js in your package.json

You can also npm i -g protoc-gen-js or npm i -g protoc-gen-js@{version} and that will make '--js_out' work everywhere at the latest or specific version specified.

Right now the only version supported is '3.21.2' but I'll try to keep it up to date as new releases are made.

@alsotang
Copy link

alsotang commented Apr 14, 2024

I don't want to downgrade my homebrew protobuf version. So I figured it out on my own.

On macOS,

  1. Install official protoc: $ brew install protobuf, then you get the protoc executable.
  2. Download protoc-gen-js from https://github.com/protocolbuffers/protobuf-javascript/releases, according to your system and cpu arch. And download protoc-gen-grpc from https://github.com/grpc/grpc-web/releases/tag/1.5.0.
  3. Run this command
      protoc -I=. echo.proto \
      --plugin="protoc-gen-grpc-web=/path/to/protoc-gen-grpc-web-1.5.0-darwin-aarch64" \
      --plugin="protoc-gen-js=/path/to/protobuf-javascript-3.21.2-osx-aarch_64/bin/protoc-gen-js" \
      --js_out=import_style=commonjs,binary:./ts-example \
      --grpc-web_out=import_style=typescript,mode=grpcweb:./ts-example

It's a bit verbose I know, but I just use the latest version of anything, and all from the official repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants