I'm trying to implement GRPC in a Node.js and Typescript project, but I'm facing an issue with generating proto files on Windows 10 using npm.
I need to run the file transpile-proto-ts.sh
:
#!/usr/bin/env bash
OUT_DIR="./src"
TS_OUT_DIR="./src"
IN_DIR="./protos"
PROTOC="$(npm bin)/grpc_tools_node_protoc"
PROTOC_GEN_TS_PATH="$(npm bin)/protoc-gen-ts"
PROTOC_GEN_GRPC_PATH="$(npm bin)/grpc_tools_node_protoc_plugin"
$PROTOC \
-I="./" \
--plugin=protoc-gen-ts=$PROTOC_GEN_TS_PATH \
--plugin=protoc-gen-grpc=${PROTOC_GEN_GRPC_PATH} \
--js_out=import_style=commonjs:$OUT_DIR \
--grpc_out=grpc_js:$OUT_DIR \
--ts_out=grpc_js:$TS_OUT_DIR \
"$IN_DIR"/*.proto
However, when I try to execute this command in git bash
: bash transpile-proto-ts.sh
I encounter the following error:
>--ts_out: protoc-gen-ts: %1 is not a valid Win32 application.
C:\Projects\GRPC\node_modules\grpc-tools\bin\protoc.js:41
throw error;
^
Error: Command failed: C:\Projects\GRPC\node_modules\grpc-tools\bin\protoc.exe --plugin=protoc-gen-grpc=C:\Projects\GRPC\node_modules\grpc-tools\bin\grpc_node_plugin.exe --plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --js_out=import_style=commonjs,binary:./protos --ts_out=./protos --grpc_out=./protos -I ./protos ./protos/example.proto
--ts_out: protoc-gen-ts: %1 is not a valid Win32 application.
at ChildProcess.exithandler (node:child_process:397:12)
at ChildProcess.emit (node:events:390:28)
at maybeClose (node:internal/child_process:1064:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) {
killed: false,
code: 1,
signal: null,
cmd: 'C:\\Projects\\GRPC\\node_modules\\grpc-tools\\bin\\protoc.exe --plugin=protoc-gen-grpc=C:\\Projects\\GRPC\\node_modules\\grpc-tools\\bin\\grpc_node_plugin.exe --plugin=protoc-gen-grpc=./node_modules/.bin/grpc_tools_node_protoc_plugin --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --js_out=import_style=commonjs,binary:./protos --ts_out=./protos --grpc_out=./protos -I ./protos ./protos/example.proto'
}