본문 바로가기
Go

Go - 문제해결: Error loading workspace: gopls was not able to find modules in your workspace.

by 맑은안개 2022. 9. 27.

VSCode에서 go 파일을 열면 다음과 같은 오류와 함께 package main 에 빨간 줄이 생겼다.

(해당 오류가 발생해도 go run 은 문제없이 동작한다.)

VSCode 하단에 다음과 같은 알림을 확인하였다.

Error loading workspace: gopls was not able to find modules in your workspace. When outside of GOPATH, gopls needs to know which modules you are working on. You can fix this by opening your workspace to a folder inside a Go module, or by using a go.work file to specify multiple modules. See the documentation for more information on setting up your workspace: https://github.com/golang/tools/blob/master/gopls/doc/workspace.md.

 

확인 결과 여러 디렉토리에 go module이 존재하는 경우 VSCode의 settings.json을 아래와 같이 변경하여야 한다.

우선, VSCode > File > Preference > settings 이동 후 "검색"에서 gopls을 검색한다.

Edit in settings.json 링크를 클릭하여 settings.json을 아래와 같이 gopls 옵션을 추가한다.

  "gopls": {
    "experimentalWorkspaceModule": true,
  }

재부팅 후 해당 알림 메시지가 없어졌는지 확인한다.

반응형