Cannot create binding for class DurableObject2 that is not exported by the script [code: 10061]

I'm editing an old version of my CloudFlare worker to add a new Durable Object called DurableObject2 When I try to deploy it, this is the error:
% npx wrangler publish -c wrangler.staging.toml --outdir dist
Your worker has access to the following bindings:
- Durable Objects:
- DO: DurableObject
- DO2: DurableObject2
...
✘ [ERROR] A request to the Cloudflare API (/accounts/wwwwww/workers/scripts/kkkkkkk) failed.

Cannot create binding for class DurableObject2 that is not exported by the script [code: 10061]

If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose
% npx wrangler publish -c wrangler.staging.toml --outdir dist
Your worker has access to the following bindings:
- Durable Objects:
- DO: DurableObject
- DO2: DurableObject2
...
✘ [ERROR] A request to the Cloudflare API (/accounts/wwwwww/workers/scripts/kkkkkkk) failed.

Cannot create binding for class DurableObject2 that is not exported by the script [code: 10061]

If you think this is a bug, please open an issue at:
https://github.com/cloudflare/workers-sdk/issues/new/choose
As you can see, the dist/index.js exports the class correctly:
% node
> a = await import('./dist/index.js')
[Module: null prototype] {
DurableObject: [class DurableObject],
DurableObject2: [class DurableObject2],
default: { fetch: [AsyncFunction: fetch] },
notFound: [Function: notFound]
}
% node
> a = await import('./dist/index.js')
[Module: null prototype] {
DurableObject: [class DurableObject],
DurableObject2: [class DurableObject2],
default: { fetch: [AsyncFunction: fetch] },
notFound: [Function: notFound]
}
In my src/index.ts there're those 2 lines:
export { DurableObject } from './durableObject'
export { DurableObject2 } from './durableObject2' // Added line
export { DurableObject } from './durableObject'
export { DurableObject2 } from './durableObject2' // Added line
The wrangler.staging.toml file is like:
name = "kkkkkkkkk"
main = "src/index.ts"

[[durable_objects.bindings]]
name = "DO"
class_name = "DurableObject"

[[durable_objects.bindings]] # added
name = "DO2"
class_name = "DurableObject2"

[[migrations]]
tag = "v1" # Should be unique for each entry
new_classes = ["DurableObject", "DurableObject2"]
name = "kkkkkkkkk"
main = "src/index.ts"

[[durable_objects.bindings]]
name = "DO"
class_name = "DurableObject"

[[durable_objects.bindings]] # added
name = "DO2"
class_name = "DurableObject2"

[[migrations]]
tag = "v1" # Should be unique for each entry
new_classes = ["DurableObject", "DurableObject2"]
I also debug which content is uploaded to PUT https://api.cloudflare.com/client/v4/accounts/wwwwwww/workers/scripts/kkkkkk?include_subdomain_availability=true&excludeScript=true, and it exports correctly the classes at the end of the content:
export {
DurableObject,
DurableObject2,
src_default as default,
defaultHeaders,
}
export {
DurableObject,
DurableObject2,
src_default as default,
defaultHeaders,
}
It works if I remove all the references to DurableObject2, keeping just DurableObject. Where do I make the mistake? wrangler: 3.15.0 system: MacOs
2 Replies
allevo
allevoOP13mo ago
The issue probably was in migrations part. I said "probably" because at the end I deleted the worker and reinstalled it. Anyway I added also a 3dh DurableObject and the error returns back. Changing the mitrations part, the deploy goes well. Bad error message.
DaniFoldi
DaniFoldi13mo ago
indeed, for every new class you need a migration where it's added (new_classes) - and old migrations need to stay as they were, so you'd have to copy your current migration, change the tag (to something unique) and put your new class into the list
Want results from more Discord servers?
Add your server