-
Notifications
You must be signed in to change notification settings - Fork 735
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
[WIP] Error if a user tries to use durable objects with a service worker #634
Conversation
Durable Objects [require Module Workers](https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/#advantages-of-migrating) to function, so we should error if we discover that a user is trying to use a durable object with a Service Worker.
🦋 Changeset detectedLatest commit: e0935f2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2001973798/npm-package-wrangler-634 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/634/npm-package-wrangler-634 Or you can use npx https://prerelease-registry.developers.workers.dev/runs/2001973798/npm-package-wrangler-634 dev path/to/script.js |
There is a little more nuance: modules are required to implement a Durable Object, but not to bind to one. Therefore, it’s only an error when the format is service worker and the Durable Object binding does not have a “script_name”. |
Ah ok...so actually...the real error is that a worker cannot have both So like...is this legal? EDIT: no, i don't think it is because you still need to export durable_object.js export class DurableObjectExample {
constructor(state, env) {
}
async fetch(request) {
return new Response('Hello World');
}
} index.js addEventListener('fetch', event => {
const example = EXAMPLE_CLASS.get('some-id');
// ...
}) wrangler.toml # ...
main = "index.js"
[durable_objects]
bindings = [
{ name = "EXAMPLE_CLASS", class_name = "DurableObjectExample", script_name = "durable_object.js" }
] |
Closing this PR and copying over discussion to the issue until I've figured out a better way to check for this |
Durable Objects require Module Workers to function, so we should error if we discover that a user is trying to use a durable object with a Service Worker.
Closes #635