Dynamic require of "cloudflare:workers" is not supported
I'm trying to create a cloudflare worker that is accessed via services by another worker. I followed the example here https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/
The worker fails to deploy with the error in the title. I aslo get this warning:
▲ [WARNING] The entrypoint src/gemini.ts has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using "service-worker" format...
Service Worker wrangler toml:
Service worker code (too long for discord)
https://pastebin.com/VraghKaZPastebin
import { GoogleGenerativeAI } from '@google/generative-ai';import {...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
3 Replies
You should use the module syntax instead of service worker syntax
@Erisa I am a bit confused by this, so in the service worker I could do something like this?
In the main worker, how would I call the service worker? Do I no longer need the services binding in wrangler.toml, and instead just directly fetch from "service worker"?
And in the export default I just route the request to different functions depending on what function I am trying to call from the "service worker"?
What is the best way to call the service worker? Set a binding in the .toml that includes the service workers url (ex. GEMINI = "geminiworker.techparadox.workers.dev" and fetch to env.GEMINI?
I got it working, thank you. Seems like the old style was less verbose but I understand the benefits of this style as well
Ah nice, sorry I was busy and missed your message