-
Notifications
You must be signed in to change notification settings - Fork 342
Open
Description
Describe the bug
When using Next.js via OpenNext on Cloudflare Workers, attempting to access a Cloudflare Agent from a Server-Side Rendered page fails at the build stage.
To Reproduce
- Checkout this repo https://github.com/talentscore/agents-ssr-issue.git (its a Minimal Reproducible Example)
- Run
npm run cf-dev - Observe the build error:
Error: Failed to collect configuration for /_not-found
[cause]: Error: Failed to load external module cloudflare:email: Error: Cannot find module 'cloudflare:email'
Expected behavior
I would expect to be able to access the agent using getAgentByName in SSR components:
import { getAgentByName } from "agents";
import { getCloudflareContext } from "@opennextjs/cloudflare";
async function MyComponent() {
const { env } = await getCloudflareContext();
const agent = await getAgentByName(env.FUN_PHRASE_AGENT, "default");
const phrase = await agent.getFunPhrase();
// ...
}This pattern would work fine in server-side worker code.
Version:
"@opennextjs/cloudflare": "^1.15.1",
"agents": "^0.3.6",
"next": "16.1.5",
"react": "19.1.5",
"react-dom": "19.1.5"
Additional context
Thanks @whoiskatrin for being so helpful at the coffee meetup in Soho London! I was recommended to create an issue by her - thanks to the whole team for all the awesome work you do with agents, it feels like the future!
Big-Tree
Metadata
Metadata
Assignees
Labels
No labels