Skip to content
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

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

@markusahlstrand markusahlstrand commented Jul 18, 2019

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
Collaborator

@hankjacobs hankjacobs commented Aug 3, 2019

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

@markusahlstrand markusahlstrand commented Aug 4, 2019

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 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

@markusahlstrand markusahlstrand commented Aug 5, 2019

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 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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants