grpc / grpc-node

gRPC for Node.js
https://grpc.io
Apache License 2.0
4.38k stars 624 forks source link

grpc-tools\bin\protoc_plugin.js:37 throw error; #2338

Open long1eu opened 1 year ago

long1eu commented 1 year ago

Problem description

Running protoc_plugin.js result in an error I can't debug or solve.

Reproduction steps

protoc --js_out=import_style=commonjs,binary:backend\cloud-run\src\proto ^
       --ts_out=generate_package_definition:backend\cloud-run\src\proto ^
       --grpc_out=grpc_js:backend\cloud-run\src\proto ^
       --plugin=protoc-gen-grpc=C:\Users\app_lab\AppData\Roaming\npm\grpc_tools_node_protoc_plugin.cmd ^
       --proto_path=backend\cloud-run\assets\proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\announcements_likes_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\announcements_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\background_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\calendar_entries_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\chats_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\comments_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\common.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\feed_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\groups_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\legal_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\messages_likes_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\messages_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\method_auth.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\notifications_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\notification_tokens_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\pace_management_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\query.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\reports_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\squads_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\users_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\workout_likes_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\workout_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\workout_share_service.proto ^
       backend\cloud-run\assets\proto\app_lab\app\v1\workout_spec_service.proto ^
       backend\cloud-run\assets\proto\google\api\annotations.proto ^
       backend\cloud-run\assets\proto\google\api\client.proto ^
       backend\cloud-run\assets\proto\google\api\field_behavior.proto ^
       backend\cloud-run\assets\proto\google\api\http.proto ^
       backend\cloud-run\assets\proto\google\api\resource.proto ^
       backend\cloud-run\assets\proto\google\longrunning\operations.proto ^
       backend\cloud-run\assets\proto\google\protobuf\any.proto ^
       backend\cloud-run\assets\proto\google\protobuf\api.proto ^
       backend\cloud-run\assets\proto\google\protobuf\descriptor.proto ^
       backend\cloud-run\assets\proto\google\protobuf\duration.proto ^
       backend\cloud-run\assets\proto\google\protobuf\empty.proto ^
       backend\cloud-run\assets\proto\google\protobuf\field_mask.proto ^
       backend\cloud-run\assets\proto\google\protobuf\source_context.proto ^
       backend\cloud-run\assets\proto\google\protobuf\struct.proto ^
       backend\cloud-run\assets\proto\google\protobuf\timestamp.proto ^
       backend\cloud-run\assets\proto\google\protobuf\type.proto ^
       backend\cloud-run\assets\proto\google\protobuf\wrappers.proto ^
       backend\cloud-run\assets\proto\google\pubsub\v1\pubsub.proto ^
       backend\cloud-run\assets\proto\google\rpc\status.proto ^
       backend\cloud-run\assets\proto\google\type\date.proto ^
       backend\cloud-run\assets\proto\grpc\health\v1\health.proto

Environment

Additional context

C:\Users\app_lab\AppData\Roaming\npm\node_modules\grpc-tools\bin\protoc_plugin.js:37
    throw error;
    ^

Error: Command failed: C:\Users\app_lab\AppData\Roaming\npm\node_modules\grpc-tools\bin\grpc_node_plugin.exe

    at ChildProcess.exithandler (node:child_process:402:12)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1100:16)
    at Socket.<anonymous> (node:internal/child_process:458:11)
    at Socket.emit (node:events:513:28)
    at Pipe.<anonymous> (node:net:301:12) {
  code: 3221225781,
  killed: false,
  signal: null,
  cmd: 'C:\\Users\\app_lab\\AppData\\Roaming\\npm\\node_modules\\grpc-tools\\bin\\grpc_node_plugin.exe'
}
--grpc_out: protoc-gen-grpc: Plugin failed with status code 1.
long1eu commented 1 year ago

Is there a way to debug this?

robido commented 1 year ago

I have the exact same issue, and I can confirm this is an issue appearing with grpc-tools version 1.12.0. If I try the command with 1.11.3, it runs fine, but not with any of the 1.12 versions. So try running this: npm install -g grpc-tools@1.11.3

Reproduced with both node v14.16.1 and the latest v19.6.0, both installed using nvm for Windows. I have the same issue wether I only type "grpc_tools_node_protoc" or I type the full command with arguments. I know the command syntax is correct, because my grpc_tools_node_protoc command used to work, but since I tried on a fresh Windows install, I can't get the command to work anymore. Also, I tried the static_codegen example it also fails.

Here is the output I get, identical as the OP:

C:\Users\robil\AppData\Roaming\nvm\v19.6.0\node_modules\grpc-tools\bin\protoc.js:41
    throw error;
    ^

Error: Command failed: C:\Users\robil\AppData\Roaming\nvm\v19.6.0\node_modules\grpc-tools\bin\protoc.exe --plugin=protoc-gen-grpc=C:\Users\robil\AppData\Roaming\nvm\v19.6.0\node_modules\grpc-tools\bin\grpc_node_plugin.exe --js_out=import_style=commonjs binary:../node/static_codegen/ --grpc_out=grpc_js:../node/static_codegen helloworld.proto

    at ChildProcess.exithandler (node:child_process:419:12)
    at ChildProcess.emit (node:events:512:28)
    at maybeClose (node:internal/child_process:1098:16)
    at Socket.<anonymous> (node:internal/child_process:456:11)
    at Socket.emit (node:events:512:28)
    at Pipe.<anonymous> (node:net:316:12) {
  code: 3221225781,
  killed: false,
  signal: null,
  cmd: 'C:\\Users\\robil\\AppData\\Roaming\\nvm\\v19.6.0\\node_modules\\grpc-tools\\bin\\protoc.exe --plugin=protoc-gen-grpc=C:\\Users\\robil\\AppData\\Roaming\\nvm\\v19.6.0\\node_modules\\grpc-tools\\bin\\grpc_node_plugin.exe --js_out=import_style=commonjs binary:../node/static_codegen/ --grpc_out=grpc_js:../node/static_codegen helloworld.proto'
}

Node.js v19.6.0

Any hints to make this command work with the latest versions?

is-jonreeves commented 1 year ago

I'm not personally experiencing the issue, but a few days a go, a colleague also run into this.

After trying to debug things, we were able to narrow it down to the protoc.exe file specifically. If he ran executable directly from cmd/powershell/bash on windows it would complain about various missing dlls. After jumping through hoops to install lots of distributables from MS, and still having no luck, we ended up downgrading the package as noted above and it is working for him.

Prior to downgrading him, we compared hashes of his and my binaries and both were the same (as you'd expect), and after downgrading was then different (also expcted).

I suspect that his windows environment is just missing some libs that mine has, but as it stands for now he isn't able to run grpc-tools@1.12.3 like the rest of the team and is having to use grpc-tools@1.11.3 instead.

yinzara commented 1 year ago

Looks like the cause of this is missing STDC DLLs that must have had some change to how they're packaged with the most recent release.

You can fix this by install the Visual Studio 2022 VCTools workload or potentially with a Visual C++ redistributable but I at least know the following works.

With choco you can run:

choco install visualstudio2022-workload-vctools --package-parameters "--includeRecommended"
JoseLion commented 9 months ago

I found you need to have these two components installed on Visual Studio Build Tools 2022:

The first one is obvious, but without the second component, grpc-tools >=1.12.0 won't work on Windows.