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.
There are several things to check before updating it.
- 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.
- Check if your installation comes from cargo or npm. On my side, I installed it using npm years ago.
wrangler configcommand won’t work on the newer version. I’m going to explain the workaround below if you’re unable to do authentication with the
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.
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:
- Create a .env file, and put this inside:
- Replace your-API-token-here with the API token from your Cloudflare account.
- Close that file and run this command (without quotes):
- Be sure to check if that env variable is set correctly. You can echo it with the
echo $CLOUDFLARE_API_TOKENcommand. 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