Skip to content

Getting error "protoc-gen-js: program not found or is not executable" when trying to compile #105

Closed
@mattwelke

Description

@mattwelke

I'm trying to use protoc to compile my Protobuf types into JavaScript. I already set up protoc on my computer by downloading it from the GitHub releases page, moving the protoc binary onto my path, and moving the includes directory into the directory on my computer recommended in its readme file.

I have the file protos/message.proto in my project:

syntax = "proto3";

option java_package = "com.mattwelke.gaprototest.server.proto";

import "google/protobuf/wrappers.proto";

message SearchRequest {
  string cid = 1;
  string dl = 2;
  string ua = 3;
  string dt = 4;
  google.protobuf.StringValue dr = 5;
}

And I have the following script to compile it:

#!/bin/env bash

protoc -I=. --js_out=. protos/message.proto

When I run that script, I get an error:

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.

In the readme file for this project, I see that it recommends compiling a different way, with different options than just all defaults, so I also tried this as my compile script:

#!/bin/env bash

protoc -I=. --js_out=import_style=commonjs,binary:. protos/message.proto

It made no difference. I got the same error.

I do have some experience with Protobuf, using it with Java and Go. For Java, I used the official Gradle plugin where you don't need to download the protoc binary or the include files, you just configure your Gradle config files and Gradle fetches the compiler and invokes it. For Go, I remember having to install a Go specific plugin. The Go plugin is well-documented in https://github.com/golang/protobuf. That makes me think the error I'm getting trying to compile to JavaScript is telling me that there is a JavaScript equivalent of that Go plugin, which I'd need to have on my system in order to compile to JavaScript.

But I can't find any documentation this plugin. I don't see anything on NPM that I can download (nothing called "protoc-gen-js" etc), nothing on the old GitHub repo for all languages (https://github.com/protocolbuffers/protobuf), and nothing on this new JavaScript-specific Protobuf repo. I tried installing the NPM package "google-protobuf" into my project, and then running the script, but I still get the error. I also tried installing that NPM package globally, thinking that perhaps there's a system binary that would be installed that I could use, but that didn't work either. Same error.

I found issue protocolbuffers/protobuf#4840 when googling my error. It talks about JS support being added in 3.0. So it might help to note that I'm using the latest version I downloaded today:

> protoc --version
libprotoc 3.21.1

I expected that compiling to JS would work because I'm using 3+.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions