Skip to content

Commit 9e85ffe

Browse files
committed
fix(cloudflare): exclude durable_objects, migrations, and workflows from prerender worker config
1 parent 09d7772 commit 9e85ffe

9 files changed

Lines changed: 96 additions & 1 deletion

File tree

.changeset/tame-teeth-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/cloudflare': patch
3+
---
4+
5+
Fixes a build crash when a custom worker entrypoint exports Durable Object classes alongside prerendered pages. The prerender worker no longer inherits `durable_objects`, `migrations`, or `workflows` from the entry worker config.

packages/integrations/cloudflare/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,13 @@ export default function createIntegration({
214214
experimental: {
215215
prerenderWorker: {
216216
config(_, { entryWorkerConfig }) {
217-
const { queues, ...restWorkerConfig } = entryWorkerConfig;
217+
const {
218+
queues,
219+
durable_objects,
220+
migrations,
221+
workflows,
222+
...restWorkerConfig
223+
} = entryWorkerConfig;
218224
return {
219225
...restWorkerConfig,
220226
name: 'prerender',
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import cloudflare from '@astrojs/cloudflare';
2+
import { defineConfig } from 'astro/config';
3+
4+
export default defineConfig({
5+
adapter: cloudflare(),
6+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@test/astro-cloudflare-prerender-durable-object",
3+
"version": "0.0.0",
4+
"private": true,
5+
"dependencies": {
6+
"@astrojs/cloudflare": "workspace:*",
7+
"astro": "workspace:*"
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
export const prerender = true;
3+
---
4+
<!doctype html>
5+
<html lang="en">
6+
<head><meta charset="utf-8" /><title>Prerender reproduction</title></head>
7+
<body><h1>This page does not use the Durable Object.</h1></body>
8+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { handle } from '@astrojs/cloudflare/handler';
2+
import { DurableObject } from 'cloudflare:workers';
3+
4+
export class ExampleDO extends DurableObject {}
5+
6+
export default { fetch: handle };
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "prerender-durable-object",
3+
"main": "./src/worker.js",
4+
"compatibility_date": "2026-01-28",
5+
"compatibility_flags": ["nodejs_compat"],
6+
"durable_objects": {
7+
"bindings": [
8+
{
9+
"name": "EXAMPLE_DO",
10+
"class_name": "ExampleDO"
11+
}
12+
]
13+
},
14+
"migrations": [
15+
{
16+
"tag": "v1",
17+
"new_sqlite_classes": ["ExampleDO"]
18+
}
19+
]
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as assert from 'node:assert/strict';
2+
import { existsSync } from 'node:fs';
3+
import { before, describe, it } from 'node:test';
4+
import { fileURLToPath } from 'node:url';
5+
import { type Fixture, loadFixture } from './test-utils.ts';
6+
7+
describe('Prerender with durable objects', () => {
8+
let fixture: Fixture;
9+
const root = new URL('./fixtures/prerender-durable-object/', import.meta.url);
10+
before(async () => {
11+
fixture = await loadFixture({
12+
root: './fixtures/prerender-durable-object/',
13+
});
14+
await fixture.build();
15+
});
16+
17+
it('builds without ERR_RUNTIME_FAILURE when wrangler config has durable_objects', () => {
18+
// Before the fix, this build crashed with:
19+
// "Class extends value undefined is not a constructor or null"
20+
// because durable_objects and migrations leaked into the prerender worker
21+
// config while `main` was overridden to the default Astro entrypoint
22+
// (which does not export the user's Durable Object classes).
23+
const distPath = fileURLToPath(new URL('dist/client/', root));
24+
assert.ok(existsSync(distPath), `Expected ${distPath} to exist after build`);
25+
});
26+
});

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)