Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Question: Is it possible to run cloudworker in debug? #109

Open
markusahlstrand opened this issue Jul 18, 2019 · 5 comments
Open

Question: Is it possible to run cloudworker in debug? #109

markusahlstrand opened this issue Jul 18, 2019 · 5 comments

Comments

@markusahlstrand
Copy link

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?

Thanks!

@hankjacobs
Copy link
Contributor

Hi @markusahlstrand,

I don't understand the question. Could you give specific examples of what you are trying to accomplish and why it currently doesn't work? Thanks!

@markusahlstrand
Copy link
Author

Hi @hankjacobs,

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!

@atmin
Copy link
Contributor

atmin commented Aug 5, 2019

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.

@markusahlstrand
Copy link
Author

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?

@atmin
Copy link
Contributor

atmin commented Aug 7, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants