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

@protobuf-ts/protoc installed globally hangs when run #475

Open
dwosk opened this issue Jan 24, 2023 · 4 comments
Open

@protobuf-ts/protoc installed globally hangs when run #475

dwosk opened this issue Jan 24, 2023 · 4 comments

Comments

@dwosk
Copy link

dwosk commented Jan 24, 2023

Running into an issue when trying to run protoc after installing the package globally.

Installation works:

$ npm install -g @protobuf-ts/protoc

changed 1 package, and audited 2 packages in 601ms

found 0 vulnerabilities

But I'm unable to run the resulting binary (script):

$ protoc --version

Running protoc just hangs.

I'm not sure if installing it globally is supported or not - it works fine when installed locally on a per-project basis.

$ which protoc
/Users/dwosk/.nvm/versions/node/v16.15.0/bin/protoc

Thanks!

@ColinLaws
Copy link
Contributor

ColinLaws commented Jan 26, 2023

I always make sure to run protoc using npx.

# with npm:
npx protoc --version 

# with yarn:
yarn protoc --version 

Also, if you're just looking to compile some .proto files, I'd recommend just doing apt install -y protobuf-compiler to install the protobuf-compiler. I wasn't sure if you were using anything else out of this package, so I figured to mention that just in case.

@dwosk
Copy link
Author

dwosk commented Jan 26, 2023

Thanks for the response @ColinLaws.

We're doing stuff cross-platform and in different environments (i.e. developer machine vs. CI) and being able to install the protoc compiler just by declaring a single npm dependency is really nice. I'm also using tonic in Rust so I'm a bit limited in how I can run protoc (can't prefix with npx I don't think).

That being said, I actually did get things working on a per-project basis:

  1. npm install -D @protobuf-ts/protoc
  2. Before compiling with tonic, set the PROTOC environment variable:
std::env::set_var("PROTOC", "../node_modules/.bin/protoc");

So far seems to be working great 🤷‍♂️

@vuki656
Copy link

vuki656 commented Apr 20, 2023

I had the same problem. The lib is supposed to install it out of the box and for example yarn protoc ... should work but it says protoc is not a known command.

When installing the @protobuf-ts/protoc as a dep then it hangs as mentioned here.

I ended up doing "generate:proto-ts": "./node_modules/.bin/protoc --ts_out ... and it works fine.

@Janrupf
Copy link

Janrupf commented Dec 30, 2023

I guess this is an issue with yarn and this package.

I observed the following:

  • yarn sets up a temporary directory which contains the bin executables from package.json files
  • yarn starts the protoc.js script (through the wrapper binary from previous step)
  • protoc.js searches the PATH, which also contains the temporary directory, finding itself
  • protoc.js starts the executable from the PATH, which means its now starting itself

(I should probably mention that I'm using yarn v4 with pnp mode)

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

4 participants