stultuss / protoc-gen-grpc-ts Goto Github PK
View Code? Open in Web Editor NEWProtocol compiler plugin for generating grpc interfaces in TypeScript.
License: MIT License
Protocol compiler plugin for generating grpc interfaces in TypeScript.
License: MIT License
This issue is related to a bug with npm
The resulting error looks like:
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c "./node_modules/.bin/node-pre-gyp install"
npm ERR! '.' is not recognized as an internal or external command,
npm ERR! operable program or batch file.
Fortunately, there is a really easy fix.
We just have to change
"install": "./node_modules/.bin/node-pre-gyp install",
to
"install": "node-pre-gyp install",
Hi, I noticed a subtle bug in protoc-gen-grpc-ts. I'm using the latest version available, v1.4.2.
Take for example this gRPC service, where the procedure Update takes a stream as input:
// updater.proto
syntax = "proto3";
package updater;
service Updater {
rpc Update (stream UpdateRequest) returns (UpdateResponse);
}
message UpdateRequest {
bytes chunk = 1;
}
message UpdateResponse {
bool is_ok = 1;
repeated string result= 2;
}
Running protoc-gen-grpc-ts creates the following TypeScript definition:
// updater_grpc_pb.d.ts
// ...
export interface IUpdaterClient {
update(callback: (error: Error | null, response: updater_pb.UpdateResponse) => void): grpc.ClientWritableStream<updater_pb.UpdateResponse>;
update(metadata: grpc.Metadata, callback: (error: Error | null, response: updater_pb.UpdateResponse) => void): grpc.ClientWritableStream<updater_pb.UpdateResponse>;
}
export class UpdaterClient extends grpc.Client implements IUpdaterClient {
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
public update(callback: (error: Error | null, response: updater_pb.UpdateResponse) => void): grpc.ClientWritableStream<warehouse_updater_pb.UpdateResponse>;
public update(metadata: grpc.Metadata, callback: (error: Error | null, response: updater_pb.UpdateResponse) => void): grpc.ClientWritableStream<updater_pb.UpdateResponse>;
}
The return type of the IUpdaterClient
and UpdaterClient
methods update
are wrong.
They should return grpc.ClientWritableStream<updater_pb.UpdateRequest>
;
The JavaScript implementation is correct though, in fact in practice I have a working gRPC system where the client has type checking disabled (via TypeScript's // @ts-ignore
).
I'm using the latest MacBook Pro 2021, with Apple M1 as CPU, which has anarm64
architecture.
Result of uname -a
:
Darwin 192.168.1.77 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:01 PDT 2021; root:xnu-8019.41.5~1/RELEASE_ARM64_T6000 arm64
I'm running Docker v20.10.10
, and in particular I'm using the node:16.13.1-alpine
image.
Trying to install protoc-gen-grpc
with the following Dockerfile
fails:
ARG NODE_VERSION=16.13.1
FROM node:${NODE_VERSION}-alpine
RUN npm install request -g
RUN npm config set unsafe-perm true
# this fails
RUN npm install protoc-gen-grpc -g
Error:
> RUN npm install protoc-gen-grpc -g:
#29 9.286 npm ERR! code 1
#29 9.286 npm ERR! path /usr/local/lib/node_modules/protoc-gen-grpc
#29 9.287 npm ERR! command failed
#29 9.287 npm ERR! command sh -c ./node_modules/.bin/node-pre-gyp install
#29 9.287 npm ERR! response status 404 Not Found on https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.1/linux-arm64.tar.gz
#29 9.287 npm ERR! node-pre-gyp info it worked if it ends with ok
#29 9.287 npm ERR! node-pre-gyp info using [email protected]
#29 9.287 npm ERR! node-pre-gyp info using [email protected] | linux | arm64
#29 9.287 npm ERR! node-pre-gyp info check checked for "/usr/local/lib/node_modules/protoc-gen-grpc/bin/grpc_tools.node" (not found)
#29 9.287 npm ERR! node-pre-gyp http GET https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.1/linux-arm64.tar.gz
#29 9.287 npm ERR! node-pre-gyp ERR! install response status 404 Not Found on https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.1/linux-arm64.tar.gz
#29 9.287 npm ERR! node-pre-gyp ERR! install error
#29 9.287 npm ERR! node-pre-gyp ERR! stack Error: response status 404 Not Found on https://node-precompiled-binaries.grpc.io/grpc-tools/v1.11.1/linux-arm64.tar.gz
#29 9.287 npm ERR! node-pre-gyp ERR! stack at /usr/local/lib/node_modules/protoc-gen-grpc/node_modules/@mapbox/node-pre-gyp/lib/install.js:67:15
#29 9.287 npm ERR! node-pre-gyp ERR! stack at processTicksAndRejections (node:internal/process/task_queues:96:5)
#29 9.287 npm ERR! node-pre-gyp ERR! System Linux 5.10.47-linuxkit
#29 9.287 npm ERR! node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/protoc-gen-grpc/node_modules/.bin/node-pre-gyp" "install"
#29 9.287 npm ERR! node-pre-gyp ERR! cwd /usr/local/lib/node_modules/protoc-gen-grpc
#29 9.287 npm ERR! node-pre-gyp ERR! node -v v16.13.1
#29 9.287 npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.5
#29 9.287 npm ERR! node-pre-gyp ERR! not ok
#29 9.293
#29 9.293 npm ERR! A complete log of this run can be found in:
#29 9.293 npm ERR! /root/.npm/_logs/2022-01-02T20_25_47_915Z-debug.log
I get errors even if I try building the library from source.
Here is the updated Dockerfile:
ARG NODE_VERSION=16.13.1
FROM node:${NODE_VERSION}-alpine
RUN npm install request -g
RUN npm config set unsafe-perm true
RUN apk add --no-cache python3 make g++
# this fails
RUN npm install --build-from-source protoc-gen-grpc -g
which yields the following error:
> RUN npm install --build-from-source protoc-gen-grpc -g:
#30 17.06 npm ERR! code 1
#30 17.06 npm ERR! path /usr/local/lib/node_modules/protoc-gen-grpc
#30 17.06 npm ERR! command failed
#30 17.06 npm ERR! command sh -c ./node_modules/.bin/node-pre-gyp install
#30 17.06 npm ERR! Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --module=/usr/local/lib/node_modules/protoc-gen-grpc/bin/grpc_tools.node --module_name=grpc_tools --module_path=/usr/local/lib/node_modules/protoc-gen-grpc/bin --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
#30 17.06 npm ERR! node-pre-gyp info it worked if it ends with ok
#30 17.06 npm ERR! node-pre-gyp info using [email protected]
#30 17.06 npm ERR! node-pre-gyp info using [email protected] | linux | arm64
#30 17.06 npm ERR! node-pre-gyp info build requesting source compile
#30 17.06 npm ERR! gyp info it worked if it ends with ok
#30 17.06 npm ERR! gyp info using [email protected]
#30 17.06 npm ERR! gyp info using [email protected] | linux | arm64
#30 17.06 npm ERR! gyp info ok
#30 17.06 npm ERR! gyp info it worked if it ends with ok
#30 17.06 npm ERR! gyp info using [email protected]
#30 17.06 npm ERR! gyp info using [email protected] | linux | arm64
#30 17.06 npm ERR! gyp info find Python using Python version 3.9.5 found at "/usr/bin/python3"
#30 17.06 npm ERR! gyp http GET https://nodejs.org/download/release/v16.13.1/node-v16.13.1-headers.tar.gz
#30 17.06 npm ERR! gyp http 200 https://nodejs.org/download/release/v16.13.1/node-v16.13.1-headers.tar.gz
#30 17.06 npm ERR! gyp http GET https://nodejs.org/download/release/v16.13.1/SHASUMS256.txt
#30 17.06 npm ERR! gyp http 200 https://nodejs.org/download/release/v16.13.1/SHASUMS256.txt
#30 17.06 npm ERR! gyp info spawn /usr/bin/python3
#30 17.06 npm ERR! gyp info spawn args [
#30 17.06 npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
#30 17.06 npm ERR! gyp info spawn args 'binding.gyp',
#30 17.06 npm ERR! gyp info spawn args '-f',
#30 17.06 npm ERR! gyp info spawn args 'make',
#30 17.06 npm ERR! gyp info spawn args '-I',
#30 17.06 npm ERR! gyp info spawn args '/usr/local/lib/node_modules/protoc-gen-grpc/build/config.gypi',
#30 17.06 npm ERR! gyp info spawn args '-I',
#30 17.06 npm ERR! gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
#30 17.06 npm ERR! gyp info spawn args '-I',
#30 17.06 npm ERR! gyp info spawn args '/root/.cache/node-gyp/16.13.1/include/node/common.gypi',
#30 17.06 npm ERR! gyp info spawn args '-Dlibrary=shared_library',
#30 17.06 npm ERR! gyp info spawn args '-Dvisibility=default',
#30 17.06 npm ERR! gyp info spawn args '-Dnode_root_dir=/root/.cache/node-gyp/16.13.1',
#30 17.06 npm ERR! gyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
#30 17.06 npm ERR! gyp info spawn args '-Dnode_lib_file=/root/.cache/node-gyp/16.13.1/<(target_arch)/node.lib',
#30 17.06 npm ERR! gyp info spawn args '-Dmodule_root_dir=/usr/local/lib/node_modules/protoc-gen-grpc',
#30 17.06 npm ERR! gyp info spawn args '-Dnode_engine=v8',
#30 17.06 npm ERR! gyp info spawn args '--depth=.',
#30 17.06 npm ERR! gyp info spawn args '--no-parallel',
#30 17.06 npm ERR! gyp info spawn args '--generator-output',
#30 17.06 npm ERR! gyp info spawn args 'build',
#30 17.06 npm ERR! gyp info spawn args '-Goutput_dir=.'
#30 17.06 npm ERR! gyp info spawn args ]
#30 17.06 npm ERR! gyp: binding.gyp not found (cwd: /usr/local/lib/node_modules/protoc-gen-grpc) while trying to load binding.gyp
#30 17.06 npm ERR! gyp ERR! configure error
#30 17.06 npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
#30 17.06 npm ERR! gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:261:16)
#30 17.06 npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:390:28)
#30 17.06 npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
#30 17.06 npm ERR! gyp ERR! System Linux 5.10.47-linuxkit
#30 17.06 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--module=/usr/local/lib/node_modules/protoc-gen-grpc/bin/grpc_tools.node" "--module_name=grpc_tools" "--module_path=/usr/local/lib/node_modules/protoc-gen-grpc/bin" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v93"
#30 17.06 npm ERR! gyp ERR! cwd /usr/local/lib/node_modules/protoc-gen-grpc
#30 17.06 npm ERR! gyp ERR! node -v v16.13.1
#30 17.06 npm ERR! gyp ERR! node-gyp -v v8.3.0
#30 17.06 npm ERR! gyp ERR! not ok
#30 17.06 npm ERR! node-pre-gyp ERR! build error
#30 17.06 npm ERR! node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --module=/usr/local/lib/node_modules/protoc-gen-grpc/bin/grpc_tools.node --module_name=grpc_tools --module_path=/usr/local/lib/node_modules/protoc-gen-grpc/bin --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v93' (1)
#30 17.06 npm ERR! node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/protoc-gen-grpc/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
#30 17.06 npm ERR! node-pre-gyp ERR! stack at ChildProcess.emit (node:events:390:28)
#30 17.06 npm ERR! node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1064:16)
#30 17.06 npm ERR! node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
#30 17.06 npm ERR! node-pre-gyp ERR! System Linux 5.10.47-linuxkit
#30 17.06 npm ERR! node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/protoc-gen-grpc/node_modules/.bin/node-pre-gyp" "install"
#30 17.06 npm ERR! node-pre-gyp ERR! cwd /usr/local/lib/node_modules/protoc-gen-grpc
#30 17.06 npm ERR! node-pre-gyp ERR! node -v v16.13.1
#30 17.06 npm ERR! node-pre-gyp ERR! node-pre-gyp -v v1.0.5
#30 17.06 npm ERR! node-pre-gyp ERR! not ok
#30 17.07
#30 17.07 npm ERR! A complete log of this run can be found in:
#30 17.07 npm ERR! /root/.npm/_logs/2022-01-02T20_34_46_825Z-debug.log
at Object. (xx\client.js:17:16) => const client = new book_grpc_pb_1.BookServiceClient("127.0.0.1:50051", grpc.credentials.createInsecure());
this.$channel = new grpc.Channel(address, credentials, channel_options);
^
TypeError: Channel's second argument (credentials) must be a ChannelCredentials
at ServiceClient.Client (xx\client.js:460:23)
at new ServiceClient (xx\client.js:987:12)
at Object. (xx\client.js:17:16)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)
at internal/main/run_main_module.js:17:11
We just upgraded from protoc-gen-grpc 1.3.1 to 2.0.2 on a Windows OS:
yarn install v1.22.5
...
error path\to\app\node_modules\protoc-gen-grpc: Command failed.
Exit code: 1
Command: .\node_modules\.bin\node-pre-gyp install
Arguments:
Directory: path\to\app\node_modules\protoc-gen-grpc
It appears that a path\to\app\node_modules\protoc-gen-grpc\node_modules\.bin
folder with node-pre-gyp in it is not being created.
Is this because node-pre-gyp was removed as a dependency?
refer issue: bufbuild/buf#358
hey there,
Thanks for all your excellent work in providing this tooling :-) We've been using this CLI since October and it's been great for us.
I am currently working with a protobuf spec that has a types map<string, TransactionType> type_mapping = 8;
Unfortunately, there is not setter generated for this field. I do get a getter and a clear function like this:
getTypeMappingMap(): jspb.Map<string, TransactionType>;
clearTypeMappingMap(): void;
I would expect a function setTypeMappingMap(value: jspb.Map<string, TransactionType>)
as part of the generated js and in the typescript declerations.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.