Skip to content

worker-shell: exec fails with "Cannot read properties of undefined (reading 'WorkspaceServiceProxy')" because the required enable_ctx_exports compat flag is undocumented #105

Description

@ryanramtin

Summary

Following the README's worker-shell quick start verbatim produces a runtime failure on the first exec, with an error naming a symbol the reader never wrote:

TypeError: Cannot read properties of undefined (reading 'WorkspaceServiceProxy')

There are two independent causes, and they produce the identical message. That's what makes this expensive: fixing one gives no signal you made progress, because the error doesn't change.

  1. The Worker doesn't re-export the class — export { WorkspaceServiceProxy } from "@cloudflare/computer"
  2. compatibility_flags is missing enable_ctx_exports, so ctx.exports is undefined

Cause 2 appears to be undocumented. The README's worker-shell section lists nodejs_compat and experimental and the Worker Loader binding, but not enable_ctx_exports. I found the flag name by grepping strings out of the workerd binary.

The failing read is backends/worker-shell/index.js:

env: { HOST: ctx.exports.WorkspaceServiceProxy({ props: workspace }) },

ctx.exports is gated behind enable_ctx_exports; without the flag the property access throws before WorkspaceServiceProxy is ever consulted — hence the misleading symbol name in the message.

Reproduce

@cloudflare/computer@0.2.0, wrangler@4.123.0, workerd@1.20260811.1.

Build the README's worker-shell quick start exactly as written, then:

curl -X POST localhost:8787/exec -H 'content-type: application/json' -d '{"cmd":"echo hi"}'

Expected: hi
Actual: TypeError: Cannot read properties of undefined (reading 'WorkspaceServiceProxy')

Adding enable_ctx_exports to compatibility_flags fixes it, provided the class is also re-exported.

Suggested fix

Either would have saved the debugging time; the first is the cheap one:

  1. Document the flag. Add enable_ctx_exports to the worker-shell setup section and the "Choosing a backend" table's Needs column, alongside the experimental flag and Worker Loader binding.
  2. Fail with a message that names the cause. Guard the ctx.exports access and throw something that distinguishes the two cases, e.g. "ctx.exports is undefined — add enable_ctx_exports to compatibility_flags" vs "WorkspaceServiceProxy is not exported from your Worker — add export { WorkspaceServiceProxy }".

Happy to open a PR for the docs change if useful.

Context

Hit while building a local rig against the isolate backend. Everything else worked well once past this — persistent filesystem across restarts, shell exec, shared store between fs and the shell, and egress control were all straightforward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions