-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not working in Cloudflare worker: Error: Code generation from strings disallowed for this context
, tough-cookie
#719
Comments
Code generation from strings disallowed for this context
, tough-cookie
Just to add some colour to this issue I think the problem (or at least one of them) is coming from the dependency on ajv for validation. Running the repro env using nitro and wrangler I get the same error message as in the AJV issue:
There are also possibly more issues with getting this to run in a non-node runtime environment. Reading through the source code I'd happily contribute PRs to rewrite the validation logic in this library to another strategy like zod, but am not sure I personally could solve this problem upstream. I also appreciate that it's not a stated goal of this library to run on every JS runtime, so if the answer is "too much complexity" or "give the AJV people a chance" I'd also understand. Any thoughts @gadicc? |
Hey @eddie-atkinson, thanks for this report too.
Having said that, I've also had issues debugging ajv before, and I think actually we're still stuck on an old release (at least for a while, I haven't checked recently) because something broke and it was so hard to work out what was happening. I also think Zod has done a great job at establishing itself, and of course, we can infer the typescript interfaces from zod schemas, it could even uncomplicate our release logic to not need to always rebuild the schema. But this would be a huuuge job, and I also think, probably worthy of a communal debate with enough time to elicit responses. If after all that, it's still something you'd like to investigate, you have my support :) I would probably start off by looking for something that converts typescript interfaces to zod code, as a starting point... as there are a loooot of them (see e.g. quoteSummary-iface.ts). |
Hi @gadicc, Thank you for taking the time to give a detailed response.
Given that this is the current workflow it feels like cutting out JSON Schema could make sense as a way of simplifying development as the source of truth is Typescript.
That's a fair call out that I didn't consider. Looking at the benchmarking done here it seems like
Is there a particular venue where you'd like to have that discussion? Here in this thread? GitHub discussions? I appreciate that this thread is, at the moment at least, a bit too hidden a way to have a discussion of this magnitude.
Yes and no, as shown by my highly scientific survey here: The real questions for me would be less the leg work of converting all the interfaces and more so how we review the changes. Keen to hear your thoughts and happy to put together a micro benchmark of some of the more gnarly interfaces to test feasibility and performance on any libraries of interest. |
Agree. Let's continue on the new issue above. GitHub discussions is also a bit too hidden. I'll reply to you there now and later this week I'll tag recent contributors in case they have any input. |
Happy to report that @eddie-atkinson's hero work in #772 has been merged. We longer have a dependency on I'm not sure about latest version of NB: the PR has been merged to |
So I've been playing around with this locally using the version of the code on I got it working, but had to tweak
So, in other words we've made some progress! Though still a couple of PRs to go before we can call this mission success. I'd love to get this working, but we need to think pretty carefully about how to keep this library agnostic to the runtime it targets. The last thing I'd like to do is add weird specific code for each runtime |
Hey @eddie-atkinson, always great to have your input here, thanks. Happy we haven't burnt you out yet ;)
Exactly! But I think you're off to a great start. And the issues you've discovered all look pretty minor.
Some other notes: a) We could also look at exactly what's being imported and if that's correct, e.g. maybe we shouldn't be loading the node environment at all outside of node. Should we be using b) Related though, in c) Depending on when you last pulled Anyways, let's see how we go. Thanks for taking a look into this, and so soon after your your other work! |
Ah, also, re (3), some maybe useful code from another project of mine. |
Hi @gadicc, I've opened a PR for the issues I call out above. Thank you once again for your thoughtful response and in-depth feedback.
Jurassic apparently, I'm using the global in the PR.
Now that we only support Node 18 and up I just dropped
Running against my branch I managed to get a CloudFlare worker returning |
Hey @eddie-atkinson, thanks so much. Was AFK over the weekend, will review now. Very exciting to finally be able to drop |
Bug Report
Describe the bug
I was using this amazing lib in Firebase Functions, but I have recently moved to Cloudflare Workers. But, I am getting
Code generation from strings disallowed for this context
error when I use in lib in production api.Note: I have enabled nodejs in cloudflare.
nodejs_compat
flag in the worker but still this error comes with this lib.Minimal Reproduction
cloudflare-module
Environment
Browser or Node: Cloudflare (with nodejs_compat enabled)
Node version (if applicable): on dev (windows 11), node version 20+
Npm version: 10+
Additional Context
Docs
Cloudflare docs (https://developers.cloudflare.com/workers/runtime-apis/web-standards/#javascript-standards) say:
Is yf lib using these? If yes, is there a way to refactor them?
[EDIT] Error
I think the cause of error might be a particular package
tough-cookie
, because when I build my nitro app with yf lib, this non-fatal error shown in terminal (though the app still builds, but api routes usingyf
lib dont work):The text was updated successfully, but these errors were encountered: