LoginSignup
2
0

More than 1 year has passed since last update.

VScodeでGoのデバッグを行う際にエラーが発生した

Last updated at Posted at 2022-12-09

概要

起動したいファイルを指定してVScodeからデバッグを実行すると以下のエラーが発生した。

Failed to launch: could not launch process: can not run under Rosetta, check that the installed build of Go is right for your CPU architecture

備忘録として解決方法を投稿する。

環境

■ PC
macOS Monterey
バージョン 12.5.1
■ チップ
Apple M1 Pro
■ CPUアーキテクチャ

e2e % uname -m
arm64

原因

自身のPCのCPUアーキテクチャがarm64にも関わらず、Goの公式よりインストールしたファイルがamd64であっためエラーになっていた。

Go version
go version go1.19.3 darwin/amd64

よって、現在のGoを削除して、arm64のファイルを再度ダウンロードした。

解決手順

Goを削除する。

% sudo rm -rf /etc/paths.d/go
% rm -fr /Users/[各々のユーザー名]/go

Goの公式よりarm64のファイルをダウンロードする。

% go version
go version go1.19.4 darwin/arm64

再度vscodeでデバックを行うと成功した。

環境変数を読み込まない

.envrcファイルを使用して環境変数を読み込んでいたが、VScodeからデバックを実行すると環境変数を参照しない現象が起きた。

.vscode/launch.jsonファイルに環境変数を追加することで解決した。

.vscode/launch.json
{
    // IntelliSense を使用して利用可能な属性を学べます。
    // 既存の属性の説明をホバーして表示します。
    // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid: 830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            // 追加
            "env": {
                "ENV": "local",
            },
        }
    ]
}

以上の設定でVScodeからGoのコードをデバッグすることができた。

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