Troubleshooting Yarn on WSL

"ERROR: There are no scenarios; must have at least one.", "/usr/bin/yarn: 20: exec: node: Exec format error"

Troubleshooting Yarn on WSL
Image from Rare Gallery

들어가며

WSL Ubuntu 22.04 LTS에서 간단한 프로젝트 하나 하기 위해 Yarn 설정을 하던 도중 다음 오류가 발생했습니다.

$ yarn
00h00m00s 0/0: : ERROR: There are no scenarios; must have at least one.

apt-keyyarn의 GPG Key를 등록하여 설치 후 실행 시에는 다음과 같은 오류가 발생했습니다.

$ yarn
/usr/bin/yarn: 20: exec: node: Exec format error

해결 방법

  • Node 공식 웹에서 NodeJS 다운로드 후 설치
    WSL2로 업그레이드하지 않고 해결하는 방법입니다.
    $ curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    $ sudo apt-get install -y nodejs
    
  • WSL2로 전환
    VSCode에서 권장하기도 하고, WSL2에서는 확실히 가능하므로 저는 그냥 WSL2로 전환했습니다. 윈도우 PowerShell에서 다음 명령어를 실행하여 자신이 사용하는 리눅스의 WSL 버전을 확인합니다.
    > wsl -l -v
    
      NAME            STATE           VERSION
    * Ubuntu-22.04    Running         1
    
    VERSION이 1이므로 WSL1을 사용 중인 것을 알 수 있습니다. 다음 명령어를 통해 WSL2로 전환합니다.
    > wsl --set-version <name> 2
    
    몇 분의 시간이 지나 다시 터미널을 실행한 뒤 yarn을 사용하면 됩니다.

참고 자료

nodejs not working, exec format error · Issue #8151 · microsoft/WSL
Version Microsoft Windows [Version 10.0.19044.1586] WSL Version WSL 2 WSL 1 Kernel Version 4.4.0-19041-Microsoft Distro Version Arch Other Software No response Repro Steps Install nodejs from Archl...