ably-js icon indicating copy to clipboard operation
ably-js copied to clipboard

[ERROR] ⨯ EvalError: Code generation from strings disallowed for this context when using Ably with Next.js on Cloudflare

Open catpddo opened this issue 5 months ago • 1 comments

I'm encountering the following error when using Ably in a Next.js project deployed on Cloudflare:

[ERROR] ⨯ EvalError: Code generation from strings disallowed for this context

Here's my setup:

  • I created the project using pnpm create cloudflare, which scaffolded a Next.js app.
  • I installed the Ably SDK (ably) and added "ably" to serverExternalPackages in next.config.ts as recommended.
  • However, whether I try to create a client using new Ably.Realtime(...) or new Ably.Rest(...), I consistently get the above error at runtime.

It seems related to the Runtime sandbox, which disallows eval or new Function.

Is there any recommended workaround for using Ably in a Cloudflare Workers environment?

Thanks in advance!

┆Issue is synchronized with this Jira Task by Unito

catpddo avatar Aug 04 '25 07:08 catpddo

Hello @catpddo !

Sorry for the delay. I looked into this but couldn’t reproduce the EvalError: Code generation from strings disallowed for this context error you described, either with Cloudflare Workers or Cloudflare Pages, both locally and when deployed.

Could you please share more details about your project configuration that might be affecting the error, or ideally provide a minimal repository that reproduces it?

You can also check and compare my minimal repository, which I used to test and deploy a Cloudflare Workers app with basic channels and presence features: https://github.com/VeskeR/ably-js-cloudflare. You might spot a difference in the implementation that caused the error.

There are no known issues with Cloudflare Workers and the latest version of ably-js, so I’m looking forward to your reply and happy to dig deeper once we have more details.

VeskeR avatar Aug 25 '25 22:08 VeskeR