Support for Custom Cloudflare Durable Objects with `cloudflare_durable` preset
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Describe the feature
Hi Nitro Team,
I'm exploring the use of Cloudflare Durable Objects with my Nuxt project and had a question regarding custom implementations.
What I'm trying to achieve:
I want to define a custom Durable Object class and access it from my API routes.
What I've tried:
- I've created a custom class, let's call it
Counter, which extendsDurableObject(from Cloudflare Workers types) withinserver/durable-objects/Counter.ts.// server/durable-objects/Counter.ts export class Counter extends DurableObject { // ... implementation ... constructor(state: DurableObjectState, env: Env) { /* ... */ } async fetch(request: Request) { /* ... */ } } - I've configured this in my
wrangler.jsoncsimilar to how one would for a standard Workers project:// wrangler.jsonc (simplified) { "durable_objects": { "bindings": [ { "name": "counter", "class_name": "Counter" } ] }, "migrations": [ { "tag": "v1", "new_sqlite_classes": ["Counter"] } ] } - So that I can asscess
counterfrom another API route (e.g.,server/api/test.ts):// server/api/test.ts export default defineEventHandler(async (counter) => { // How to correctly get the Durable Object namespace and stub here? // const counter = event.context.cloudflare.env.counter; // const id = counter.idFromName("my-counter"); // const stub = counter.get(id); // ... });
Problem:
When I attempt to deploy my application, I encounter the following error:
Your Worker depends on the following Durable Objects, which are not exported in your entrypoint file: Counter..
Question:
- Is it generally supported to define and use custom Durable Object classes (like my Counter example) with presets in Nitro?
- If so, what is the correct way to ensure these custom DO classes are properly exported or recognized by Nitro's build process to avoid the deploy error?
Any pointers to relevant documentation or examples of this setup would be very helpful.
Thanks for your time and help!
Any guidance or clarification on this would be greatly appreciated!
Thanks.
Additional information
- Would you be willing to help implement this feature?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the custom class in server/durable-objects/Counter.ts, its wrangler.jsonc durable_objects and migrations entries, and the server/api/test.ts route. Verify the deployment entrypoint recognizes Counter and that the API route can obtain its namespace and stub without the reported unexported Durable Object error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend, cloud
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100