Prompt Buddy logoPrompt Buddy

cloudflare · Cloudflare Workers Docs

Migrate To Module Workers Migrate from Service Workers to ES Modules

A guide for converting Cloudflare Workers from the legacy Service Worker syntax to the modern ES modules format, including changes to code structure, bindings, and environment variables.

Import to Prompt Buddy

Derived skill

Files assembled from official documentation

Viewing SKILL.md

Migrate To Module Workers Migrate from Service Workers to ES Modules

A guide for converting Cloudflare Workers from the legacy Service Worker syntax to the modern ES modules format, including changes to code structure, bindings, and environment variables.

When To Use

Use when you need to refactor existing Service Worker code to ES modules to enable features like Durable Objects, D1, or Workers AI and to improve execution performance.

Reference Files

FileContainsUse For
SKILL.mdEntry point: scope, routing table, and workflow.Start here.
docs/workers-migrate-to-module-index-from-service-es-modules-workflow-guide.mdA guide detailing the process, advantages, and binding changes required to migrate Cloudflare Workers from the Service Worker format to ES Modules.Questions about a guide detailing the process, advantages, and binding changes required to migrate Cloudflare Workers from the Servic...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke.textA code comparison demonstrating the transition from a service worker event listener pattern to an ES module export pattern for Cloudflare Workers.Exact payloads, commands, or snippets shown in A code comparison demonstrating the transition from a service worker event listener pattern to an ES module export pa...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-2.textA text example demonstrating how to convert a Service Worker redirect logic into a Module Worker fetch handler.Exact payloads, commands, or snippets shown in A text example demonstrating how to convert a Service Worker redirect logic into a Module Worker fetch handler.
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-3.textA text-based example demonstrating the structural differences and migration steps from Service Worker syntax to ES Modules in Cloudflare Workers.Exact payloads, commands, or snippets shown in A text-based example demonstrating the structural differences and migration steps from Service Worker syntax to ES Mo...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-4.textA text example demonstrating how to update KV namespace bindings when migrating from Service Worker syntax to ES Modules in Cloudflare Workers.Exact payloads, commands, or snippets shown in A text example demonstrating how to update KV namespace bindings when migrating from Service Worker syntax to ES Modu...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-5.textA code comparison demonstrating the transition from service worker addEventListener syntax to ES module export syntax for Cloudflare Workers.Exact payloads, commands, or snippets shown in A code comparison demonstrating the transition from service worker addEventListener syntax to ES module export syntax...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-6.textA code example demonstrating the transition from Service Worker syntax to ES Module syntax in Cloudflare Workers.Exact payloads, commands, or snippets shown in A code example demonstrating the transition from Service Worker syntax to ES Module syntax in Cloudflare Workers.
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-7.textA code example demonstrating the transition from service worker syntax to ES module syntax using an async function and environment bindings.Exact payloads, commands, or snippets shown in A code example demonstrating the transition from service worker syntax to ES module syntax using an async function an...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-8.textA wrangler configuration file demonstrating the transition from service worker syntax to ES module format for Cloudflare Workers.Exact payloads, commands, or snippets shown in A wrangler configuration file demonstrating the transition from service worker syntax to ES module format for Cloudfl...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-9.textA wrangler configuration file demonstrating the schema and variable setup for migrating from service workers to module workers.Exact payloads, commands, or snippets shown in A wrangler configuration file demonstrating the schema and variable setup for migrating from service workers to modul...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-10.textA text comparison showing the transition from service worker addEventListener syntax to ES module export syntax for Cloudflare Workers.Exact payloads, commands, or snippets shown in A text comparison showing the transition from service worker addEventListener syntax to ES module export syntax for C...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-11.textA code example demonstrating the syntax transition from Service Worker event listeners to the ES Modules export default fetch handler.Exact payloads, commands, or snippets shown in A code example demonstrating the syntax transition from Service Worker event listeners to the ES Modules export defau...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-12.textA code example demonstrating the transition from Service Worker syntax to ES Modules using the cloudflare:workers environment import.Exact payloads, commands, or snippets shown in A code example demonstrating the transition from Service Worker syntax to ES Modules using the cloudflare:workers env...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-13.textA code example demonstrating the transition from Service Worker syntax to ES Modules using the cloudflare:workers environment import.Exact payloads, commands, or snippets shown in A code example demonstrating the transition from Service Worker syntax to ES Modules using the cloudflare:workers env...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-14.textA code comparison demonstrating the transformation of a scheduled event listener from the Service Worker syntax to the ES Modules syntax.Exact payloads, commands, or snippets shown in A code comparison demonstrating the transformation of a scheduled event listener from the Service Worker syntax to th...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-15.textA code example demonstrating the structural transition from Service Worker syntax to ES Module syntax for Cloudflare Workers.Exact payloads, commands, or snippets shown in A code example demonstrating the structural transition from Service Worker syntax to ES Module syntax for Cloudflare...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-16.textA code example demonstrating the transition from service worker event listeners to ES module exports for Cloudflare Workers.Exact payloads, commands, or snippets shown in A code example demonstrating the transition from service worker event listeners to ES module exports for Cloudflare W...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-17.textA code example demonstrating how to convert a service worker scheduled event handler into a module worker format using export default.Exact payloads, commands, or snippets shown in A code example demonstrating how to convert a service worker scheduled event handler into a module worker format usin...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-18.textA text comparison showing the transition from service worker addEventListener syntax to ES module export default syntax for Cloudflare Workers.Exact payloads, commands, or snippets shown in A text comparison showing the transition from service worker addEventListener syntax to ES module export default synt...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-19.textA text representation of the legacy Service Worker fetch event listener format used before migrating to ES Modules.Exact payloads, commands, or snippets shown in A text representation of the legacy Service Worker fetch event listener format used before migrating to ES Modules.
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-20.textA text comparison showing the transformation of a Service Worker fetch event handler into an ES Module format for Cloudflare Workers.Exact payloads, commands, or snippets shown in A text comparison showing the transformation of a Service Worker fetch event handler into an ES Module format for Clo...
examples/workers-migrate-to-module-index-from-service-es-modules-cloudflare-worke-21.textA text comparison showing the syntax transformation from a Service Worker fetch event listener to a Module Worker export.Exact payloads, commands, or snippets shown in A text comparison showing the syntax transformation from a Service Worker fetch event listener to a Module Worker exp...

What This Skill Covers

  • This guide will show you how to migrate your Workers from the Service Worker ↗ format to the ES modules ↗ format.
  • Main sections: Advantages of migrating, Migrate a Worker, Bindings, Bindings in Service Worker format, Bindings in ES modules format.

Workflow

  1. Open the most relevant file under docs/ for the exact documented workflow and wording.
  2. Open schemas/ files for exact structured contracts.
  3. Open examples/ files for concrete requests, commands, snippets, and manifests.
  4. Do not add behavior or configuration that is not present in the attached source files.

Canonical source: https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/index.md