cloudflare / cloudflare/workers-sdk

no_bundle:true in generated wrangler.json causes SSR pages to return [object Object] in production

Open
#14,978 2 comments 0 reactions 0 assignees View on GitHub
package:vite-plugin package:wrangler
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
187

Description

## Bug description

When deploying an Astro SSR app (using the `@astrojs/cloudflare` adapter, which bundles with `@cloudflare/vite-plugin`) to Cloudflare Workers, **server-rendered pages return a bare `[object Object]` body** (HTTP 200, `Content-Type: text/html`, body length 15) instead of the rendered HTML.

Locally (`astro dev` / `wrangler dev`) everything works fine. The problem only appears in production after `wrangler deploy`.

## Root cause analysis

The generated `dist/server/wrangler.json` contains `"no_bundle": true` and ESModule rules. The generated `dist/server/entry.mjs` is a small file that only re-exports from relative chunks:

```js
import { w } from "./chunks/worker-entry_XXX.mjs";
export { w as default };
```

With `no_bundle: true`, Wrangler deploys these as separate modules, but the relative chunk imports are not resolved at runtime in the Worker, so the handler ends up being an empty/odd object that gets serialized as `[object Object]` in the response body.

Setting `"no_bundle": false` in `dist/server/wrangler.json` before deploying makes Wrangler bundle everything into a single self-contained Worker, which fixes the issue completely.

## Repro

1. Astro SSR project with `@astrojs/cloudflare` adapter (which uses `@cloudflare/vite-plugin`).
2. `npm run build` produces `dist/server/wrangler.json` containing `"no_bundle": true`.
3. `npx wrangler deploy -c dist/server/wrangler.json`.
4. Request any server-rendered page in production → response body is `[object Object]`.

Workaround that works: patch the generated `wrangler.json` to set `no_bundle: false` before deploying (e.g. a post-build script).

## Expected behavior

With `no_bundle: true`, the relative imports between emitted chunks should resolve correctly at runtime in the deployed Worker (either via proper module rules, or by inlining the chunks). Alternatively, the plugin could default to bundling into a single file.

## Environment

- `@cloudflare/vite-plugin`: 1.39.2
- `@astrojs/cloudflare`: 13.6.1
- `astro`: 6.4.3
- `wrangler`: 4.104.0

Contributor guide

Open the contributing guide

Research direction

Run npm run build and inspect dist/server/wrangler.json and dist/server/entry.mjs, then deploy with npx wrangler deploy -c dist/server/wrangler.json to reproduce the production response. Trace how no_bundle and the relative chunk imports are handled; done means the deployed SSR page returns rendered HTML instead of [object Object].

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript, vite
Domain
backend, cli, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.