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.

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

报告相同问题?

悬赏问题

  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?