-
Notifications
You must be signed in to change notification settings - Fork 323
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
Challenges and Solutions for Using Types in Turborepo with Service Bindings #3113
Comments
Is the problem here that your tRPC server has an import on |
@petebacondarwin In short, tRPC server imports cloudflare:workers because types like WorkerEntrypoint can’t be directly referenced from @cloudflare/workers-types as they aren’t exported. |
@petebacondarwin https://github.com/j4tmr/test-cfw-types. The project is still a bit complex. To put it simply, both the API and services are Cloudflare Workers, while the frontend is a Next.js project. You just need to
Then, start the API project, and the build should pass. The main issue is what I mentioned above, which aligns with your understanding—using cloudflare:workers in Turborepo has some optimization challenges. |
@j4tmr—to clarify here, are you trying to use the |
@penalosa |
For worker-to-worker communication you should be able to treat // worker-a/index.ts
export class WorkerA extends WorkerEntrypoint {
helloWorld() {
return "Hello World"
}
} // worker-configuration.d.ts in worker-b
interface Env {
...
WORKER_A: Service<typeof import("../worker-a/index.ts)").WorkerA>
...
} However, this does get complicated with RPC client-server boundaries, since using types that extend I'd be curious to know more about your use case though—are you directly exposing a worker entrypoint over trpc? How does that work? |
@penalosa I have many workers for handling different services, and one worker for the API (api-worker) using tRPC to call other service workers, which communicate via RPC. The issue appears to be related to TypeScript types. For example, a service worker method that has a TypeScript return type causes the API worker to depend on these types. This results in the entire service type being dependent on |
I am using Cloudflare Workers with tRPC and Turborepo. I wrote a service with Workers and created an API using Service Bindings.
My issue is that when compiling the tRPC client, it references 'cloudflare:workers', which is defined in @cloudflare/workers-types but is not an exported module. My solution is, in the project where the tRPC client adding
in the
tsconfig.json
.This temporarily solves the issue, but in the future, any other app that needs to use the tRPC API will also need to add a reference to @cloudflare/workers-types in their tsconfig. So I’m considering whether it would be better to directly add an export for types like WorkerEntrypoint in the 'cloudflare:workers' module.
The text was updated successfully, but these errors were encountered: