connectrpc / connect-es

The TypeScript implementation of Connect: Protobuf RPC that works.
https://connectrpc.com/
Apache License 2.0
1.37k stars 79 forks source link

@connectrpc/connect-node fails with bun #877

Closed erikreppel closed 1 year ago

erikreppel commented 1 year ago

Describe the bug connect-node currently does work with bun likely due to an outdated dependency (see this issue: https://github.com/oven-sh/bun/issues/5122)

Would be great to be able to use connect with bun!

$ bun run index.ts
100 |   var keys = Object.keys(add), i = keys.length;
101 |   while (i--)
102 |     origin[keys[i]] = add[keys[i]];
103 |   return origin;
104 | 
105 | }, kCustomPromisifiedSymbol = Symbol.for("util.promisify.custom"), promisify = function promisify2(original) {
                                                                                                                                                                                                       ^
TypeError: The "original" argument must be of type Function
      at promisify2 (node:util:105:196)
      at /Users/erikreppel/dev/projects/vibe/services/grpcserver/node_modules/@connectrpc/connect-node/dist/cjs/compression.js:24:6
      at globalThis (/Users/erikreppel/dev/projects/vibe/services/grpcserver/node_modules/@connectrpc/connect-node/dist/cjs/compression.js:58:0)

To Reproduce Follow the node getting started (https://connectrpc.com/docs/node/getting-started/#start-a-server) using bun instead of node

If you encountered an error message, please copy and paste it verbatim. If the bug is specific to an RPC or payload, please provide a reduced example.

Environment (please complete the following information):

 "@connectrpc/connect": "^1.1.2",
    "@connectrpc/connect-fastify": "^1.1.2",
    "@connectrpc/connect-node": "^1.1.2",

If your problem is specific to bundling, please also provide the following information:

srikrsna-buf commented 1 year ago

Hey! It's great to see connect usage with newer runtimes like bun. But unfortunately I don't think there's anything we can do to make this work, this has to be resolved in bun. The bun issue you linked seems to the one to follow.

Jarred-Sumner commented 1 year ago

@erikreppel please file this issue in Bun’s repository. If it works in Node but doesn’t work in Bun, it’s a bug in Bun.

is-jonreeves commented 3 months ago

I realize this issue is closed, but it wasn't clear if it was resolved or not.

I was on my way to try connectrpc with elysia and hono, and stumbled across this issue, so figured it was worth trying first.

I tested using fastify@4.28.1 on bun@1.1.21 with connect@1.4.0 appears to work fine now.

/package.json ```json { "name": "poc-bun-fastify-connectrpc", "scripts": { "start": "bun ./src/server.ts", "generate": "buf generate ./proto" }, "devDependencies": { "@bufbuild/buf": "^1.35.1", "typescript": "^5.5.4" }, "dependencies": { "@bufbuild/protobuf": "^1.10.0", "@connectrpc/connect": "^1.4.0", "@connectrpc/connect-fastify": "^1.4.0", "@connectrpc/connect-node": "^1.4.0", "fastify": "^4.28.1" } } ```
/buf.gen.yaml ```yaml version: v2 plugins: - remote: buf.build/bufbuild/es:v1.10.0 out: src/generated/ opt: target=ts - remote: buf.build/connectrpc/es:v1.4.0 out: src/generated/ opt: target=ts ```
/proto/eliza.proto ```proto syntax = "proto3"; package connectrpc.eliza.v1; message SayRequest { string sentence = 1; } message SayResponse { string sentence = 1; } service ElizaService { rpc Say(SayRequest) returns (SayResponse) {} } ```
/src/server.ts ```ts import { fastify } from 'fastify'; import { fastifyConnectPlugin } from '@connectrpc/connect-fastify'; import type { ConnectRouter } from '@connectrpc/connect'; import { ElizaService } from './generated/eliza_connect'; // Define the Connect RPC Routes const routes = (router: ConnectRouter) => router .service(ElizaService, { say: async (req) => ({ sentence: `You said: ${req.sentence}` }), }); // Create a Fastify server const server = fastify(); // Register the Connect RPC Routes with the server await server.register(fastifyConnectPlugin, { routes }); // Define a basic Root Route server.get('/', (_, res) => res.type('text/plain').send(`Server Time: ${new Date().toISOString()}`)); // Start the server await server.listen({ host: 'localhost', port: 8080 }); console.log('server is listening at', server.addresses()); ```