Generate js file from proto file with protoc v21.1
Command used -
protoc.exe --js_out=import_style=commonjs,binary:. employees.proto
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.
I encountered the same issue upgrading to version 3.21.1 from 3.20.0
I'm having a same issue. Is there any solution yet?
Really looking forward to this fix. Would love to help in any way if I can :)
I'm having the same issue on macOS:
protoc-gen-js: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--js_out: protoc-gen-js: Plugin failed with status code 1.
I don't see protoc-gen-js in any of the binary downloads; couldn't figure out whether or not there is a separate install for this or if it should be "included" in the protoc binary as before.
I've seen that the release notes for v21.0-rc1 link to a document explaining that javascript has been moved out of the main repository to allow it to evolve independently of protoc. However, the new protobuf-javascript repository does not provide any instructions that helps me resolve this issue.
Note that the v20.1 release provides an additional js asset that I also wasn't able to make use of. Couldn't find any useful instructions.
I downgraded to v20.1 and then I don't get this problem.
PS: I'm new to installing protobuf from the official releases; I've used brew in the past, but it seems the homebrew folks are having some problems with v20.1 as well, with v3.19.4 being the most recent working version.
I also encountered the same issue when I use the v3.21.0. which verson can I use ? I want to generate js File
I have the same on 3.21.2
@haberman 21.x breaks JS and there's no known workaround for OSX / brew Can you take a look and provide some guidance, please
no release notes on removing JS
no way to downgrade
brew install [email protected]
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
Running `brew update --auto-update`...
Warning: No available formula with the name "[email protected]". Did you mean [email protected]?
brew install [email protected]
Error: [email protected] has been disabled because it is a versioned formula!
no releases on the js split
https://github.com/protocolbuffers/protobuf-javascript
no build instructions on the js split
https://github.com/protocolbuffers/protobuf-javascript
the latest known working js release has no build instructions either
workaround on OSX / brew:
brew install protobuf@3
brew link --overwrite protobuf@3
Related https://github.com/Homebrew/homebrew-core/pull/105712 https://github.com/Homebrew/homebrew-core/pull/105812
Installed protobuf 21.4 with homebrew, which uses protoc 3.21.4, and also got the same protoc-gen-js: program not found or is not executable error.
The suggestion by @clehene worked like a charm
protobuf 21.4 Win x64 Compiler:
'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.
My findings.
Clone protobu-javascript source code
git clone https://github.com/protocolbuffers/protobuf-javascript
cd protobuf-javascript/
bazel build //generator:protoc-gen-js # It might be better to use bazelisk as a launcher for bazel.
protoc-gen-js's executable is in bazel-bin/generator/
$ ls bazel-bin/generator/protoc-gen-js
bazel-bin/generator/protoc-gen-js
Pass the path to the plugin option in protoc
protoc --plugin=/path/to/protoc-gen-js
Someday there might be a formal migration guide from the protocolbuffers team.
Thanks for that, @johejo. I'm trying to figure out how in the world to get this working in a Bazel context, in which we use a third party JS gRPC proto generator (rules-proto-grpc), and that thing calls into protoc, expecting protoc to know what to do to generate JS protos. Ugh..
We are currently working on releasing binaries for protoc-gen-js, but it should be possible to build. You can find some better examples of the plugin invocation here: https://github.com/protocolbuffers/protobuf-javascript/blob/main/docs/index.md
A simpler workaround(other than downgrading) is to download the executable from https://github.com/protocolbuffers/protobuf-javascript/releases and add it to your PATH. Then it will work as expected
A simpler workaround(other than downgrading) is to download the executable from https://github.com/protocolbuffers/protobuf-javascript/releases and add it to your PATH. Then it will work as expected
I can validate this is a valid workaround. After downloading the protofub-javascript release .zip (protobuf-javascript-3.21.2-linux-x86_64.zip, in my case) and copying bin/protoc-gen-js into the same directory as protoc, this command will execute successfully:
protoc --js_out=js proto/simple.proto
My system is 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
A simpler workaround(other than downgrading) is to download the executable from https://github.com/protocolbuffers/protobuf-javascript/releases and add it to your PATH. Then it will work as expected
I can validate this is a valid workaround. After downloading the protofub-javascript release .zip (
protobuf-javascript-3.21.2-linux-x86_64.zip, in my case) and copyingbin/protoc-gen-jsinto the same directory asprotoc, this command will execute successfully:
protoc --js_out=js proto/simple.protoMy system is
5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
This does not work on my machine, it's missing some dynamically linked libraries: libwinpthread-1.dll, libstdc++-6.dll. I do Angular/Javascript development a lot of years, and know some things are complicated with dependencies. But this protoc thing really kicks it off. It's like i just want to build the sample gRPC-Web Echo Example and it immediately stops that i cannot even compile those simple proto files... i mean This javascript issue seems to be open since half a year ?!? is nobody seriously using this proto stuff with javascript ? And why there is no simple workaround, i mean why even the pre-build protoc-js has even dependencies ?!?!?!?!?! Why not build a complete selfcontained executable that is working on it's own, really....
Not sure it will help @nickwinger, but you may find it easier to work with Buf's protoc plugins that generates javascript/typescript. For my project, we adopted Buf's connect-go, connect-web, and the es plugins, and it has worked great for us. It generates more readable code as well.
@meling thank you, sounds promising, i‘ll have a look :) i got more and more into the world that with JavaScript (and nodejs) you can do everything. And google with chrome and angular where pushing limits. And now this proto thing does not like JavaScript no more ?!?…
I was working trying to create protoc compilations for any version and multiple language
now, I can replicated the error in a isolated container
check https://github.com/pablodz/protoc-generator/tree/feat/error-protoc-node
run
#recommended
make loadenvs
make generate verbose=true
I hope this will help to fix errors easily
If you're forced to downgrade and are running into issues with window in strict mode, you can use commonjs_strict: https://github.com/protocolbuffers/protobuf/issues/9152#issuecomment-1411231302
This worked for me (after npm install google-protobuf):
Create an executable file protoc-gen-js.sh:
#!/usr/bin/env sh
cd "$(dirname "$0")"
node ./node_modules/google-protobuf/google-protobuf.js "$@"
And then when running protoc:
protoc --plugin=protoc-gen-js=./protoc-gen-js.sh --js_out=import_style=commonjs,binary:./gen-javascript --proto_path=protobuf/src path/to/my.proto
Okay never mind, that didn't work at all.
v3.22.0 still does not work:
protoc: stdout: . stderr: protoc-gen-js: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--js_out: protoc-gen-js: Plugin failed with status code 1.
My findings.
Clone protobu-javascript source code
git clone https://github.com/protocolbuffers/protobuf-javascript cd protobuf-javascript/ bazel build //generator:protoc-gen-js # It might be better to use bazelisk as a launcher for bazel.
protoc-gen-js's executable is inbazel-bin/generator/$ ls bazel-bin/generator/protoc-gen-js bazel-bin/generator/protoc-gen-jsPass the path to the plugin option in protoc
protoc --plugin=/path/to/protoc-gen-jsSomeday there might be a formal migration guide from the protocolbuffers team.
This worked for us, thanks @johejo! It's definitely a headache compared to how it used to "just work" though.
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.
There is an official first-party solution: if you npm install grpc-tools, then you simply use grpc_tools_node_protoc (which is inside node_modules/.bin) instead of protoc. See documentation.
This way I managed to do without protoc-gen-js.
@pietrodn I wouldn't consider that a solution. grpc-tools latest version is still only on protobuf version 3.19.1, which is before this issue even occurs.
Thanks for the info, I wrongly assumed that at least the official grpc-tools would be up to date. The more I use grpc, the more disappointed I am.
I also build the protoc-gen-js myself now. For future reference, the command protoc --plugin=/path/to/protoc-gen-js is not correct.
You have to use protoc --plugin=protoc-gen-js=/path/to/protoc-gen-js when protoc-gen-js is not the path.
I also build the
protoc-gen-jsmyself now. For future reference, the commandprotoc --plugin=/path/to/protoc-gen-jsis not correct.You have to use
protoc --plugin=protoc-gen-js=/path/to/protoc-gen-jswhen protoc-gen-js is not the path.
Can you explain how you built protoc-gen-js? I'm trying to create a grpc client with Angular and javascript to use with my existing grpc server. I have .proto files but nothing is working to generate .js/.ts files.