Last November, we announced the beta release of a full rewrite of Wrangler, our CLI for building Cloudflare Workers. Since then, we’ve been working round the clock to make sure it's feature complete, bug-free, and easy to use. We are proud to announce that Wrangler goes public today for general usage, and can’t wait to see what people build with it!
Rewrites can be scary. Our goal for this version of Wrangler was backward compatibility with the original version, while significantly improving the developer experience. I'd like to take this opportunity to present 10 reasons why you should upgrade to the new Wrangler!
1. It's simpler to install:
A simpler way to get started.
Previously, folks would have to install @cloudflare/wrangler
globally on a system. This made it hard to use different versions of Wrangler across projects. Further, it was hard to install on some CI systems because of lack of access to a user's root folder. Sometimes, folks would forget to add the @cloudflare
scope when installing, confusing them when a completely unrelated package was installed and didn't work as expected.
Let's fix that. We've simplified this by now publishing to the wrangler
package, so you can run npm install wrangler
and it works as expected. You can also install it locally to a project's package.json
, like any other regular npm package. It also works across a much broader range of CPU architectures and operating systems, so you can use it on more machines.
This makes it a lot more convenient when starting. But why stop there?
2. Zero config startup:
Get started with zero configuration
It's now much simpler to get started with a new project. Previously, you would have to create a wrangler.toml
configuration file, and fill it in with details about your cloudflare account, how the project was structured, setting up a custom build process and so on. We heard feedback from many of you who would get frustrated during this step, and how it would take many minutes before you could get to developing a simple Worker.
Let's fix that. You no longer need to create a configuration file when starting, and none of the fields are mandatory. Wrangler infers details about your account and project as you start developing, and you can add configuration incrementally when you need to.
In fact, you don't even need to install Wrangler to start! You can create a Worker (say, as index.js
) and use npx
(a utility that comes installed with node.js
) to fetch Wrangler from the npm registry and start developing immediately!
This is great for extremely simple Workers, but why stop there?
3.
We noticed users would struggle to set up a project with Wrangler, even after they'd installed Wrangler and configured wrangler.toml
. Most users want to set up a package.json
, commonly use typescript
to write code, and set up git
to track changes in this project. So, we expanded the wrangler init <project name>
command to set up a production grade project. You can optionally choose to use typescript
, install the official type definitions for Workers, and use git
to track changes.
My favorite trick here is to pass -y
to accept all questions without asking. Try running npx wrangler init my-worker -y
in your terminal today!
One line to set up a full Workers project
4.
Wrangler typically runs a development server on our global network, setting up a local proxy when developing, so you can develop against a "real" environment in the cloud. This is great for making sure the code you develop will behave the same in development, and after you deploy it to production. The trade-off here is it's harder to develop code when you have a bad Internet connection, or if you're running tests on a CI machine. It's also marginally slower to iterate while coding. Users have asked us for a long time to be able to 'run' their code locally on their machines, so that they can iterate quickly and run tests in environments like CI.
Wrangler now lets you develop on your machine by simply calling wrangler dev --local
, and no additional configuration. This is powered by Miniflare, a fully featured simulator of the Cloudflare Workers runtime. You can even toggle across 'edge' and 'local' modes by tapping the 'L' hotkey when developing; however you prefer!
Local mode, powered by Miniflare.
5. Tail any Worker, any time:
Tail your logs anywhere, anytime.
It's useful to be able to "tail" a Worker's output to a terminal, and see what's going on in real time. While you can already view these logs in the Workers dashboard, some people are more comfortable seeing the logs in their terminal, and then slicing and dicing to debug any issues that may be occuring. Previously, you would have to checkout a Worker's repository locally, install dependencies, and then call wrangler tail
in the project folder. This was clearly cumbersome, and relied on developer expertise to see something as simple as a Worker's logs.
Now you can simply call npx wrangler tail <worker name>
in your terminal, without any configuration or setup, and immediately see the logs that you expect. We use this ourselves to quickly inspect our production Workers and see what's going on inside them!
6. Better warnings and errors, everywhere:
One of the worst feelings a developer can face is being presented with an error when writing code, and not knowing how to fix it and proceed. We heard feedback from many of you who were frustrated with the lack of error messages, and how you would spend hours trying to figure out what went wrong. We've now added new error and warning messages, so you can easily spot the problems in your code. When possible, we also include steps you can follow to fix your Worker, including things that you can simply copy and paste! This makes Wrangler much more friendly to use, and we promise the experience will only get better.
7. On-demand developer tools for debugging:
We introduced initial support for debugging Workers in Wrangler in September which enables debugging a Worker directly on our global network. However, getting started with debugging was still a bit cumbersome, because you would have to start Wrangler with an --inspect
flag, then open a special page in your browser (chrome://inspect
), configuring it to detect Wrangler running on a special port, and then launching the debugger. This would also mean you might have lost any debugging messages that were logged before you opened the Chrome developer tools.
We fixed this. Now you don't need to pass any special flags when starting up. You can simply hit the D
hotkey when developing and a developer tools instance pops up in your browser. And by buffering the messages before you even start up the devtools, you don't lose any logs or errors! You can also use VS Code developer tools to directly hook into your Worker's debugging session!
8. A modern module system:
Modern JavaScript isn't simply about the syntax that the language supports, but also writing code as modules, and leveraging the extremely broad ecosystem of community libraries and frameworks. Previously, Wrangler required that you set up webpack
or a custom build with bundlers (like rollup
, vite
, or esbuild
, to name a few) to consume libraries and modules. This introduces a lot of friction, especially when starting a new project and trying out new ideas.
Now, support for npm modules comes out of the box, with no extra configuration required! You can install any package from the npm registry, organize your own code with modules, and it all works as expected. We're also introducing an experimental node.js
compatibility mode for using node.js
modules that wouldn't previously work without setting up your own polyfills! This means you can use popular frameworks and libraries that you're already familiar with while focusing on delivering value to your users.
9. Closes many outstanding issues:
A rewrite should be judged not just by the new features that are implemented, but by how many existing issues are resolved. We went through hundreds of outstanding issues and bugs with Wrangler, and are happy to say that we solved almost all of them! Across the board, every command and feature got a facelift, bug fixes, and test coverage to make sure it doesn't break in the future. Developers on using Cloudflare Workers will be glad to hear that simply upgrading Wrangler will immediately fix previous concerns and problems. Which leads us to my absolute favorite feature...
10. A commitment to improve:
The effort into building wrangler v2.0, visualised.
Wrangler has always been special software for us. It represents the primary interface that developers use to interact and use Cloudflare Workers, and we have major plans for the future. We have invested time, effort and resources to make sure Wrangler is the best tool for developers to use, and we're excited to see what the future holds. This is a commitment to our users and community that we will only keep improving on this foundation, and folks can expect their feedback and concerns to be heard loud and clear.