rescript-schema icon indicating copy to clipboard operation
rescript-schema copied to clipboard

Usage of eval doesn't allow the library to run on Cloudflare workers

Open joshderochervlk-simplisafe opened this issue 1 year ago • 5 comments

Just wanted to open up an issue to track this. I am currently working on a Remix site that is deployed to a Cloudflare worker and it throws an error due to the use of eval.

EvalError: Code generation from strings disallowed for this context
    at new Function (<anonymous>)
    at build (index.js:31463:10)
    at init (index.js:31522:19)
    at parseAnyOrRaiseWith (index.js:31531:13)
    at parseAnyWith (index.js:31539:11)
    at index.js:32491:12
    at async loader (index.js:32488:14)
    at async callRouteLoaderRR (index.js:3797:16)
    at async callLoaderOrAction (index.js:2877:16)
    at async Promise.all (index 0)

Hi, I'm sorry for the inconvenience. It's a known limitation of the library. I can't remove it, so at least tried to highlight it as much as possible in the Readme: https://github.com/DZakh/rescript-schema/blob/8b808657464c9885d32dcacf9e2026eb21a420fe/README.md?plain=1#L9.

I've chosen to suffer ~5% of users to make the library an ultimate solution for the remaining 95%. It was a difficult decision, but unfortunately, without eval, it would be impossible to achieve both top-notch DX, performance, and bundle size.

As a possible solution, I've seen someone mentioning a tool called safe-eval . I didn't try it myself, but it might actually work.

Otherwise, I'd choose https://github.com/glennsl/rescript-json-combinators for the specific use case.

DZakh avatar Jan 31 '24 09:01 DZakh

I did catch that on the Readme, just wanted to know if it was something that could/should be fixed. This isn't the first lib that I have had issues with on Cloudflare, so it's not unique to this package.

jderochervlk avatar Feb 01 '24 20:02 jderochervlk

safe-eval isn't a viable solution since this library's intended to be used on the client-side as well, and safe-eval is on server-side only. Plus, presumably the perf hit from using vm would negate all this JITing effort

chenglou avatar Feb 25 '25 11:02 chenglou

I got an idea how to implement a fallback like using a plugin system, but it's quite some work, which I'll probably have time for in half a year. Still possible

DZakh avatar Feb 25 '25 13:02 DZakh

Oh that would be awesome!

Let me know if there is anything we can do to help!

jderochervlk avatar Mar 03 '25 14:03 jderochervlk

Won't be a blocker soon https://github.com/cloudflare/workerd/pull/4142 🤩

DZakh avatar May 18 '25 09:05 DZakh

Shouldn't this issue be closed as resolved?

Fixed in:

  • https://github.com/cloudflare/workerd/pull/4142

ImBIOS avatar Jul 23 '25 04:07 ImBIOS