Skip to content

Dynamic require of "ws" is not supported #1

Description

@astanciu

Trying to use the bridge inside a Cloudflare Worker locally, using wrangler dev. I'm getting this error:

[code-bridge] Failed to connect: Dynamic require of "ws" is not supported
error when starting dev server:
Error: Dynamic require of "http" is not supported
    at __require (/Users/user/project/app/apps/auth-svc/node_modules/.vite/deps_auth_svc/chunk-PR4QN5HX.js:11:9)
    at instrumentNodeNetwork (/Users/user/project/app/node_modules/.pnpm/@just-every+code-bridge@0.1.5/node_modules/@just-every/code-bridge/dist/index.mjs:366:27)
    at startBridge (/Users/user/project/app/node_modules/.pnpm/@just-every+code-bridge@0.1.5/node_modules/@just-every/code-bridge/dist/index.mjs:948:24)

I'm guessing the problem is it detects the platform as Node, then this kicks in:
https://github.com/just-every/code-bridge/blob/main/src/websocket.ts#L56-L58

Edit: Found a workaround. This gets it to detect the platform as worker

  process.versions.node = undefined;
  startBridge(...)

Edit2: Don't think the current websocket based architecture is going to work with Cloudflare Workers as is. I'm getting:

Cannot perform I/O on behalf of a different request. I/O objects (such as streams, request/response bodies, and others) created in the context of one request handler cannot be accessed from a different request's handler. This is a limitation of Cloudflare Workers which allows us to improve overall performance. (I/O type: Native)

I tried starting the bridge at different scopes, global, in the worker's constructor, and in the worker's fetch function, but all lead to this error.

WS is probably not the right thing for request-based stateless edge function.

Leave this here for visibility

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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