Go项目: package project/name is not in GOROOT
从github上下载golang项目到本地运行go build编译,IDE上显示raycast.go: package raycast/engine is not in GOROOT (D:\Go\src\raycast\engine)错误
下面是项目结构:

golang使用gopath或者gomod模式进行包管理,我使用gomod模式
export GO111MODULE=on
在E:\raycastergo\目录下运行go mod init raycastergo与go mod tidy命令。目录下会生成两个文件。就可以解决上面出现的raycast.go: package raycast/engine is not in GOROOT (D:\Go\src\raycast\engine)错误
go.mod
go.sum
注意:go mod init后面所跟的名称raycastergo必须与项目名称raycastergo一致

否则会报错:
raycast.go: package raycast/engine is not in GOROOT (D:\Go\src\raycast/engine)

浙公网安备 33010602011771号