【メモ】【WSL2】【Ubuntu】【yarn】yarn serve を実行して「00h00m00s 0/0: : ERROR: [Errno 2] No such file or directory: 'serve'」となった時の解決方法
前提
$ uname -a Linux DESKTOP-CDBO27E 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
何が起きた?
- yarn serve 実行したい
- cmdtest を apt install でインストールする
- yarn serve 実行
- 「00h00m00s 0/0: : ERROR: [Errno 2] No such file or directory: 'serve'」が表示される
$ yarn Command 'yarn' not found, but can be installed with: sudo apt install cmdtest $ sudo apt install cmdtest ... $ yarn serve 00h00m00s 0/0: : ERROR: [Errno 2] No such file or directory: 'serve'
Why ?
調べていくと stackOverflowの以下の回答に行き着いた。
以下原文の日本語訳を引用。
ディストリビューションなどが明記されていないのであれなのですが,ざっくりといえば多くのディストリビューションにおいてはディストリビューションが提供しているパッケージはyarnpkg,yarnが独自のdebやrpmのリポジトリで配布してるのがyarnになっていることが多いようです.また,ディストリビューションの配布しているパッケージではyarnコマンドではなくyarnpkgコマンドに置き換えられていることがあります.(DebianやUbuntuなどでディストリビューションの配布しているyarnpkgパッケージには/usr/bin/yarnは含まれていません.)
しかし,これは理由というよりは結果です.なぜディストリはyarnではなくyarnpkgでこのパッケージを提供しているのでしょうか.それはyarnpkgとは全く関係のないpythonのパッケージであるcmdtest(Ubuntuのバージョンによってはデフォルトでインストールされていることがあるようですが)が/usr/bin/yarnをリザーブしており,yarnはcmdtestのエイリアスになっていることがあるようです.
曰く、Debian や Ubuntu などのディストリビューションの yarn は Python の cmdtest というパッケージに対するエイリアスになっているらしい。
言われてみると apt installを実行した際にPython のパッケージがインストールされていて「何故?」と疑問に思ったが、こういうことだったのか。
Reading state information... Done The following additional packages will be installed: python3-cliapp python3-markdown python3-packaging python3-pygments python3-pyparsing python3-ttystatus Suggested packages: python3-xdg python-markdown-doc python-pygments-doc ttf-bitstream-vera python-pyparsing-doc The following NEW packages will be installed: cmdtest python3-cliapp python3-markdown python3-packaging python3-pygments python3-pyparsing python3-ttystatus 0 upgraded, 7 newly installed, 0 to remove and 195 not upgraded. Need to get 808 kB of archives. After this operation, 4394 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 python3-cliapp all 1.20180812.1-3build1 [44.5 kB] Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 python3-pyparsing all 2.4.6-1 [61.3 kB] Get:3 http://archive.ubuntu.com/ubuntu focal/main amd64 python3-packaging all 20.3-1 [26.8 kB] Get:4 http://archive.ubuntu.com/ubuntu focal/main amd64 python3-markdown all 3.1.1-3 [59.3 kB] Get:5 http://archive.ubuntu.com/ubuntu focal/universe amd64 python3-ttystatus all 0.38-4 [14.7 kB] Get:6 http://archive.ubuntu.com/ubuntu focal/universe amd64 cmdtest all 0.32.14.gcdfe14e-1 [21.8 kB] Get:7 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 python3-pygments all 2.3.1+dfsg-1ubuntu2.2 [579 kB] Fetched 808 kB in 2s (426 kB/s) Selecting previously unselected package python3-cliapp.
解決方法
解決方法は以下のリンク先に記載の通りになる。
下記コマンドを順に実行すればOK。
$ sudo apt remove cmdtest $ sudo apt remove yarn $ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - $ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list $ sudo apt-get update $ sudo apt-get install yarn -y $ yarn v yarn run v1.22.19
yarn のインストールが終わった後、yarn serve が実行できることを確認👍。
❯ yarn serve yarn run v1.22.19 $ serve UPDATE AVAILABLE The latest version of `serve` is 14.1.2 ┌──────────────────────────────────────────────────┐ │ │ │ Serving! │ │ │ │ - Local: http://localhost:3000 │ │ - On Your Network: http://172.24.35.23:3000 │ │ │ │ Copied local address to clipboard! │ │ │ └──────────────────────────────────────────────────┘
以上。