Skip to content

definePlugin TDZ: "Cannot access 'SIMPLE_ID' before initialization" — every route 500s on Cloudflare Workers (0.17.1 & 0.17.2) #1370

@gndzkrkc

Description

@gndzkrkc

Summary

On a Cloudflare Workers (D1 + R2) Astro SSR site that registers native plugins via definePlugin, upgrading emdash from 0.15.0 → 0.17.1 or 0.17.2 makes every route return HTTP 500 at runtime. astro check and astro build pass cleanly — the failure only appears at runtime under workerd:

ReferenceError: Cannot access 'SIMPLE_ID' before initialization
    at defineNativePlugin (dist/server/chunks/adapt-sandbox-entry_*.mjs:796:3)
    at definePlugin        (dist/server/chunks/adapt-sandbox-entry_*.mjs:791:10)
    at createPlugin        (dist/server/chunks/wait-until_*.mjs:758:10)
    at <module init>       (dist/server/chunks/wait-until_*.mjs:1014:3)
    at <module init>       (dist/server/chunks/adapt-sandbox-entry_*.mjs:770:5)

SIMPLE_ID is a const declared later in the same emitted chunk than a top-level createPlugindefinePlugindefineNativePlugin call that reads it — i.e. a temporal-dead-zone / circular-init ordering problem in the bundled output.

Environment

  • emdash 0.17.2 (also reproduced on 0.17.1; 0.15.0 is unaffected)
  • @emdash-cms/cloudflare 0.17.2, @emdash-cms/admin 0.17.2
  • astro 6.4.4, @astrojs/cloudflare 13.6.1
  • wrangler 4.98.0 / workerd, Node 24, pnpm 11
  • output: 'server', emdash({ database: d1({binding:'DB'}), storage: r2({binding:'MEDIA'}) })
  • 3 native plugins registered via definePlugin (entrypoint module paths)

Reproduction

  1. pnpm build
  2. npx wrangler dev --config dist/server/wrangler.json
  3. curl http://127.0.0.1:8799/500, log shows the trace above (every route).

The adapter build emits no_bundle: true, so a real wrangler deploy behaves identically.

Notes / what was tried

  • Reproduces with the docs-minimal Cloudflare config too (no custom vite.optimizeDeps / ssr.noExternal). The integration itself sets ssr.noExternal: ["emdash", "@emdash-cms/admin"], so emdash is re-bundled into the worker regardless — which appears to be where Rollup flattens the circular init into a TDZ.
  • 0.17.1 and 0.17.2 both affected; 0.15.0 works fine on the identical setup.

Is this a known issue, and is there a recommended config or a fix version? Happy to provide a minimal reproduction repo if useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions