[ERROR] ⨯ EvalError: Code generation from strings disallowed for this context when using Ably with Next.js on Cloudflare
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"toserverExternalPackagesinnext.config.tsas recommended. - However, whether I try to create a client using
new Ably.Realtime(...)ornew 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!
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.