cloudflare / cloudflare/cloudflare-docs

React‑Router / Vite + Cron Triggers: Local‑dev workflow & docs clarification

Open
#23,818 4 comments 4 reactions 5 assignees Assigned to @irvinebroque View on GitHub
content:new documentation product:workers stale
Dominant language
MDX
Stars
5.2k
Forks
16.7k
Avg merge
2d 6h
Merged PRs (30d)
337

Description

### Proposed changes

- https://developers.cloudflare.com/workers/runtime-apis/handlers/scheduled/
- https://developers.cloudflare.com/workers/framework-guides/web-apps/react-router/
- Any other framework guides where it maybe applicable

Please add guidance that covers how to use Cron Triggers with a full‑stack React Router (v7) project created via the Cloudflare Vite plugin.

Why? The current pages show how to add a scheduled() handler, but do not mention that:

Vite must build the server bundle before wrangler dev (otherwise ‑‑local fails with Could not resolve “virtual:react‑router/server-build”).

Using --test-scheduled exposes /__scheduled, which conflicts with React‑Router routing

Thank you

### Subject Matter

Local‑development workflow for projects that generate a “virtual:react‑router/server-build” module and need Cron Triggers.

### Content Location

A new “Troubleshooting / local development” subsection in the React‑Router guide, beneath “Develop locally”, linking to the Scheduled‑handler page.

### Additional information

Symptoms we hit in real projects:

`npx wrangler dev` (no build) crashes with Could not resolve “virtual:react‑router/server-build”.
- Unless you know that you need to run `npx vite build` first.

`wrangler dev --test-scheduled` 404s at` /__scheduled` because React Router picks the route.

The only way I got the cron to work locally was to comment out all the fetch logic in the `workers/app.ts`, and leave the scheduled function, then `npx wrangler dev --test-scheduled --config ./wrangler.jsonc` .

```
// import { createRequestHandler } from "react-router";

// declare module "react-router" {
// export interface AppLoadContext {
// cloudflare: {
// env: Env;
// ctx: ExecutionContext;
// };
// }
// }

// const requestHandler = createRequestHandler(
// () => import("virtual:react-router/server-build"),
// import.meta.env.MODE
// );

export default {
// async fetch(request, env, ctx) {
// return requestHandler(request, {
// cloudflare: { env, ctx },
// });
// },
async scheduled(
controller: ScheduledController,
env: Env,
ctx: ExecutionContext
) {
console.log("cron processed");
},
} satisfies ExportedHandler;

```

I also tried this configuration in my wrangler file, but react-router still captured the request.

```
"assets": {
"directory": "./build/client/",
"not_found_handling": "single-page-application",
"run_worker_first": ["/__scheduled*"]
},
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.