반응형
gopls was not able to find modules in your workspace.When outside of GOPATH, gopls needs to know which modules you are working on ~
* Mac
* vscode
* Golang 1.20
상황
vscode에서 go run main.go를 실행하는데 발생한 에러입니다.
해결
1. vscode 설정 수정
*이 방법은 인터넷에서 가장 많이 찾은 방법이지만 현재 2023.07.26 기준으로 (제가 했을 때)안됩니다.*
먼저 settings에 들어가서 gopls을 검색 후 settings.json에 들어갑니다.
들어간 후 “gopls” : { “"build.expandWorkspaceToModule": true,”} 입력해주면 됩니다.
* 저는 Invalid settings: gopls setting "experimentalWorkspaceModule" is deprecated 발생하여 작동하지 않습니다. 뜨면서 해결되지 않았습니다.
2. Golang이 directory를 인식하지 못하는걸 인식할 수 있도록 수정
최상의 directory(root 폴더)에 go.work를 생성해준 후 go work use <폴더 위치>를 통해 go.work에 폴더 위치를 추가해줍니다.
저는 2번으로만으로 해결되었습니다.
반응형
'Golang > TroubleShooting' 카테고리의 다른 글
./room.go:39:6: main redeclared in this block (0) | 2023.08.09 |
---|---|
package command-line-arguments is not a main package (0) | 2023.08.09 |
package is not in GOROOT (0) | 2023.07.26 |
./room.go:39:6: main redeclared in this block (0) | 2023.07.26 |
current directory is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using: (0) | 2023.07.26 |