I'm looking for an easy way to debug cloudflare workers wonder if this is possible with the cloudworker? I'm currently using more or less the runtime.js library from cloudworker to patch the node environment before starting the worker and it works pretty good, but it doesn't seem like the runtime is exposed? Is this possible, could it be possible or would it be better to do this in a separate project?
The text was updated successfully, but these errors were encountered:
What I'm trying to accomplish is debug multiple files in visual studio code, rather than compiling to a single text file. I wonder if there is a way to achieve this with the cloudworker lib or if it's a different use case? The examples I've seen with for instance unit tests loads the worker as a text file which I assume will make debugging in vs-code difficult? Thanks!
If you enable source map for your webpacked result, you can debug the original multiple source files just fine.
As Cloudworker is not a lib, but an executor of your single-file worker code, you cannot just set a breakpoint (like you cannot set a breakpoint inside a string, which is eval()ed at runtime), then 'Debug > Start Debugging' and expect the debugger to stop (I will be happy to be corrected if there's an easy way).
But you can put a debugger statement in your code and then 'Start Debugging' to initiate a debugging session.
This might be a stupid question, but is there an advantage to loading the script in a node vm sandbox? Would there be a downside to just adding shims for the cloudflare runtime and executing the script straight away? That way breakpoints would work just as in any other node program with no webpack required. Or is it more a question about that cloudworker isn't a lib, but an executor?
The advantage is dev and prod environments are as similar, as possible.
The disadvantage is harder to debug.
Before Cloudworker existed, I actually used the approach you're describing (doing feature detection and requireing/patching stuff when runtime is Node. Webpack the thing in the publish script (dead code elimination takes care of Node polyfills) and upload to Cloudflare). Yes, debugging is straightforward, but the code is uglier and environments differ in subtle ways, which can lead to hard to debug errors when the application is more complex. Also, harder to replicate errors in prod.
I guess it can be very feasible approach for simple apps, though.