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

@connectrpc/connect-node fails with bun #877

Closed
erikreppel opened this issue Oct 12, 2023 · 3 comments
Closed

@connectrpc/connect-node fails with bun #877

erikreppel opened this issue Oct 12, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@erikreppel
Copy link

Describe the bug
connect-node currently does work with bun likely due to an outdated dependency (see this issue: oven-sh/bun#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",
  • Frontend framework and version: n/a
  • Node.js version: v18.18.0 (bun version 1.0.6)
  • Browser and version: n/a

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

  • Bundler and version: bun 1.0.6
@erikreppel erikreppel added the bug Something isn't working label Oct 12, 2023
@srikrsna-buf
Copy link
Member

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
Copy link

@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
Copy link

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 [email protected] on [email protected] with [email protected] appears to work fine now.

/package.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
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
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
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());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants