dsjzmrz78089 2019-08-20 11:21
浏览 844
已采纳

如何修复VS Code错误:Go项目无法解决“无法使用cwd确定当前软件包的导入路径”

I'm following tutorials and I think I may have missed something.

I have a Go project located at:

/Users/just_me/development/testing/golang/example_server

The contents are: main.go

package main

import "fmt"

func main() {

    fmt.Println("hi world")
}

I have a ~/go directory.

go env shows:

GOPATH="/Users/just_me/go"
GOROOT="/usr/local/Cellar/go/1.12.9/libexec"

I installed the suggested packages in VSCode.

When I save my main.go I get:

Not able to determine import path of current package by using cwd: /Users/just_me/development/testing/golang/example_server and Go workspace: 
/Users/just_me/development/testing/golang/example_server>

How do I fix this?

  • 写回答

1条回答 默认 最新

  • doubo4824 2019-08-20 12:04
    关注

    Since your package is outside of $GOPATH, you may need to create a module file.

    You'll need to init your go module using

    go mod init your.import/path
    

    Change the import path to whatever you like.

    This way you set the import path explicitly, which might help fix it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置