この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
Introduction
Wranglerとは、Cloudflare Workers用のCLIツールです。
簡単なコマンド入力でWorkers用プロジェクトの作成から
ビルド、デプロイまでをやってくれる便利ツールになってます。
Wranglerには現在、version1とversion2の2系統があるのですが、
Wrangler v1のサポートを2023/2/16に廃止すると連絡がきてました。
マイグレーションガイドもありますし。忘れないうちにアップグレードしておきます。
Upgrade v1 to v2
まずはv1のアンインストールをしましょう。
# npmを使ってた場合
% npm uninstall -g @cloudflare/wrangler
# Cargoを使ってた場合
% cargo uninstall wrangler
Removing /path/your/.cargo/bin/wrangler
npmやyarnなどのパッケージマネージャを使ってwranglerをインストールします。
% npm install -g wrangler
問題なくインストールできました。
% wrangler --version
⛅️ wrangler 2.9.1
-------------------
v1プロジェクトをv2で確認
v1で作成したWorkersプロジェクトをv2で使う場合、
エラーや警告が発生する可能性があります。
手元のv1プロジェクトをv2でうごかしてみたら
↓のようなエラーや警告がいくつか表示されました。
% wrangler dev
⛅️ wrangler 2.9.1
-------------------
▲ [WARNING] Processing wrangler.toml configuration:
- ? Ignored: "type":
Most common features now work out of the box with wrangler, including modules, jsx,
typescript, etc. If you need anything more, use a custom build.
- Deprecation: "zone_id":
This is unnecessary since we can deduce this from routes directly.
- The "route" field in your configuration is an empty string and will be ignored.
Please remove the "route" field from your configuration.
- The "account_id" field in your configuration is an empty string and will be ignored.
Please remove the "account_id" field from your configuration.
✘ [ERROR] Missing entry-point: The entry-point should be specified via the command line (e.g. `wrangler dev path/to/script`) or the `main` config field.
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose
いろいろ出ますが、詳細や修正方法も表示してくれるので、
そんなに苦労することはないと思います。
なお、エラーや警告が発生する非推奨フィールドについては、
このあたりを参照してください。
Summary
今回はWranglerのv1からv2へのマイグレーションについて紹介しました。
2023年2月16日以降でも、2023年8月1日までは
重要なセキュリティアップデートなどは継続されますが、
手順も簡単ですし、とくに理由がないなら
いまのうちに移行しておいたほうがいいかと思います。