Get 10% OFF hosting service at AlexHost with this voucher code: L59CD15KZ9Y6

Important steps to update deprecated Wrangler for Cloudflare Worker deployment

I’ve used Wrangler to run several static sites on Cloudflare Worker for years. Recently, I got a deprecation warning about the deprecated Wrangler. Although it’s still working, it’s also disturbing to see a such deprecated warning message. So, I decided to update it, but I realized there are steps to do that.

Preparations

There are several things to check before updating it.

  1. It needs at least NodeJS version 16. I use the nvm tool to manage the NodeJS version on my machine. To switch, I can just run: nvm use 16.
  2. Check if your installation comes from cargo or npm. On my side, I installed it using npm years ago.
  3. The wrangler config command won’t work on the newer version. I’m going to explain the workaround below if you’re unable to do authentication with the wrangler login command.

Update

The updating process is simple. You just need to remove the deprecated version and install the latest version. If you’re using the npm, here’s the command:

npm uninstall -g @cloudflare/wrangler && npm install -g wrangler

Here’s what it does:

  • The first command will uninstall the deprecated version.
  • If the first command succeeds, it will install the latest version of Wrangler.
  • If the first command fails, the second command won’t run.

After updating

As mentioned, you can’t use the wrangler config command to authenticate with the Cloudflare API. You must use the wrangler login command now.

But, there are some cases where wrangler login is not feasible. You need this if you’re using Cloud IDE like me. For such cases, you can do these:

  1. Create a .env file, and put this inside: export CLOUDFLARE_API_TOKEN=your-API-token-here
  2. Replace your-API-token-here with the API token from your Cloudflare account.
  3. Close that file and run this command (without quotes): source .env
  4. Be sure to check if that env variable is set correctly. You can echo it with the echo $CLOUDFLARE_API_TOKEN command. Ensure you see your token printed on the terminal.

The last thing to do is to make sure you can deploy to your Cloudflare Worker properly by running this command:

wrangler publish --env production

Categories: Internet  

Tags: cloudflare