LoginSignup
2
0

【VSCode】Goツールで発生したエラーについて

Last updated at Posted at 2023-12-10

この記事は、海洋大技術系サークル Advent Calender 2023の10日目です。

1. はじめに

こんにちは!
主にバックエンドを中心に開発している、大学生です!
最近Goを書く機会が多いのですが、VScodeでGoの拡張機能の依存関係のパッケージインストールでエラーにハマったのでそちらについて書いていきたいと思います。

2. 何をしたのか

VSCodeでGoツールをインストールするために、パレッドで以下のようにGo: Install/Update toolsを行いました。
スクリーンショット 2023-12-09 23.54.33.png

スクリーンショット 2023-12-10 0.04.02.png

3. 発生したエラー

Go: Install/Update toolsを実行したところ以下のようなエラーが発生しました。

Installing github.com/cweill/gotests/gotests@v1.6.0 FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "/opt/homebrew/bin/go install -v github.com/cweill/gotests/gotests@v1.6.0",
 "stdout": "",
 "stderr": "runtime/cgo\n# runtime/cgo\nxcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun\n"
}

エラー内容としては、
missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun\n
ということで、xcrumコマンドが/Library/Developer/CommandLineTools/usr/bin/xcrun\nで見つからないというものでした。
どうやら、xcrumコマンドを使えるようにするために何かインストールしなければいけないみたいです。

4. 解決方法

xcrunは、macOSで提供されているXcode Command Line Toolsに含まれているので、こちらをインストールするために以下のコマンドを実行します。

xcode-select --install

インストール後は、xcrunがインストールされているか確認するために、以下のコマンドで実行します。

xcrun --version

xcrun version {数字}.が表示されればインストール完了です。

再度上記の2で行ったパレッドでGo: Install/Update toolsを行い、VSCodeの出力で以下の結果のようになればGoツールのインストールができました。

Tools environment: GOPATH=/Users/{username}/go
Installing 5 tools at /Users/{username}/go/bin in module mode.
  gotests
  goplay
  dlv
  staticcheck
  gopls

Installing github.com/cweill/gotests/gotests@v1.6.0 (/Users/{username}/go/bin/gotests) SUCCEEDED
Installing github.com/haya14busa/goplay/cmd/goplay@v1.0.0 (/Users/{username}/go/bin/goplay) SUCCEEDED
Installing github.com/go-delve/delve/cmd/dlv@latest (/Users/{username}/go/bin/dlv) SUCCEEDED
Installing honnef.co/go/tools/cmd/staticcheck@latest (/Users/{username}/go/bin/staticcheck) SUCCEEDED
Installing golang.org/x/tools/gopls@latest (/Users/{username}/go/bin/gopls) SUCCEEDED

All tools successfully installed. You are ready to Go. :)

5. まとめ

今回は、VSCodeの拡張機能の依存パッケージをインストールする際に発生したエラー対処についてまとめました。
意外な詰まりポイントだったので、参考になれば幸いです。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0