Some notes on the DX


I have been trying to develop a very simple website using contentful and pugjs to display articles all generated by a CF worker on the fly. First I am not sure it is a valid use case for a CF worker but at least I have understood it is possible from the documentation.

So, the project is using: pugjs for the templating, contentful for the headless cms, cloudworker-router to manage some specific routes. From the main index.js file, a css file using tailwind is generated. Everything works fine at first when doing a wrangler dev.

Now, let’s me share my dev experience …

  1. Any changes on a files are detected with a delay of 3s - There is only 20 files in the src folder. Once the change is detected, I have to wait another 4s to have Built successfully, built project size is 344 KiB. Script modified; context reset. and another few sec to upload the file into CF. => feedback loop is too long (same behaviour OSX and inside Vagrant)
  2. Once the build is updated, I try to refresh the page, I get an JS error in the terminal Uncaught (in response) Error: internal error due to Worker exceeded resource limits . The code change is one char in the code nothing fancy. => no rational here from a dev POV, file get updated, build recreated, almost same code, but get an error.
  3. The other type of error I have been experimented is the new code is not being used even when wrangler says: ‘Build successfully’.
  4. So I have to stop wrangler and restart it at every code changes. Please note I have subscribe to the pay plan to make sure I am not hitting any kind on limitation from the free plan.
  5. Now, I have been trying to debug … just to understand what is causing CPU / RAM consumption. But it seems everything is in a black box. The preview feature displays a nice UI but there is very nothing much we can do, we can see the sub request, this is a nice feature, but apart from that … well nothing to help.
  6. I also subscribe to Argos to get more log through cloudflared. But it seems to be only access log not very helpful to debug.
  7. Webpack minifies and optimises the JS so trying to set a break point is almost impossible. If I set NODE_ENV to development then the compiler complains because templates cannot use EVAL. I guess webpack in dev mode does not really compile files.
  8. Wrangler sometime get lost, and panic but does not crash and end up with the similar behaviour states in the point 3.

Did I miss something obvious ? Does my current use case is not suitable for the current CF Worker ? Will CF Worker Unbound more appropriate ?

On the bright node, once published the code seems to running fine with no errors! I know that dev mode is pretty recent and some improvements will be made. Keep up the good work :wink:


The most appropriate answer to all of these is, welcome to cloudflare workers :wink:

It has it’s limitations, but once you learn them and work around it using trial and error (there’s no debug). You’ll be fine! Look for loops and too large scripts, even just initializing the script can take 50ms of CPU-time. So it’s all about using optimized code and not just “add a package” like with Nodejs.

If you’re dynamically generating CSS in the worker, then that’s a given CPU-monster.