Go Debug delve dlv 错误无法导入

Go Debug delve dlv Error Could Not Import

提问人:Calvin 提问时间:1/18/2023 最后编辑:Calvin 更新时间:1/19/2023 访问量:279

问:

源代码: https://github.com/Calvinn097/gqlgentest

安装 go 1.19.5

DLV 版本为 1.20.1,从 vscode 命令安装Go: Install/Update Tools

PS W:\workS\testgql> dlv version
Delve Debugger
Version: 1.20.1
Build: $Id: 96e65b6c615845d42e0e31d903f6475b0e4ece6e $

按照 https://gqlgen.com/ 设置示例待办事项

.vscode/launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}/server.go",
            // "envFile": "${workspaceFolder}/.env"

            
        }
        
    ]
}

我使用 vscode F5 启动 dlv

按 F5 后,调试控制台输出将生成此错误

Starting: W:\usergo\go\bin\dlv.exe dap --listen=127.0.0.1:29675 from W:\workS\testgql
DAP server listening at: 127.0.0.1:29675
Build Error: go build -o W:\workS\testgql\__debug_bin.exe -gcflags all=-N -l .\server.go
# crypto/x509/pkix
W:\go\src\crypto\x509\pkix\pkix.go:10:2: could not import encoding/asn1 (EOF)
# crypto/rsa
W:\go\src\crypto\rsa\rsa.go:28:2: could not import crypto/internal/boring/bbig (EOF)
W:\go\src\crypto\rsa\rsa.go:30:2: could not import crypto/rand (EOF)
# crypto/ed25519
W:\go\src\crypto\ed25519\ed25519.go:19:13: could not import crypto/rand (EOF)
# vendor/golang.org/x/crypto/cryptobyte
W:\go\src\vendor\golang.org\x\crypto\cryptobyte\asn1.go:8:16: could not import encoding/asn1 (EOF)
# net/textproto
W:\go\src\net\textproto\textproto.go:31:2: could not import net (EOF)
# github.com/mitchellh/mapstructure
W:\usergo\go\pkg\mod\github.com\mitchellh\[email protected]\decode_hooks.go:7:2: could not import net (EOF)
# text/template
W:\go\src\text\template\exec.go:15:2: could not import text/template/parse (EOF)
W:\go\src\text\template\exec.go:131:15: invalid operation: s.node == nil (operator == not defined on untyped nil)
W:\go\src\text\template\exec.go:134:31: s.tmpl.ErrorContext undefined (type *Template has no field or method ErrorContext)
W:\go\src\text\template\exec.go:215:15: invalid operation: t.Tree == nil (operator == not defined on untyped nil)
W:\go\src\text\template\exec.go:215:24: t.Root undefined (type *Template has no field or method Root)
W:\go\src\text\template\exec.go:218:22: t.Root undefined (type *Template has no field or method Root)
W:\go\src\text\template\exec.go:234:19: invalid operation: tmpl.Tree == nil (operator == not defined on untyped nil)
W:\go\src\text\template\exec.go:234:31: tmpl.Root undefined (type *Template has no field or method Root)
W:\go\src\text\template\exec.go:439:26: tmpl.Root undefined (type *Template has no field or method Root)
W:\go\src\text\template\template.go:138:41: invalid operation: nt.Tree == nil (operator == not defined on untyped nil)
W:\go\src\text\template\template.go:138:41: too many errors
# vendor/golang.org/x/net/idna
W:\go\src\vendor\golang.org\x\net\idna\idna10.0.0.go:28:2: could not import golang.org/x/text/unicode/norm (EOF) (exit status 2)

去.mod

module gqluser

go 1.16

require (
    github.com/99designs/gqlgen v0.16.0
    github.com/vektah/gqlparser/v2 v2.2.0
)

我尝试重新安装 go,但失败了go version go1.19.5 windows/amd64

在另一台设备上 f5 运行没有问题,如果我创建并设置为运行打印某些内容,它就会成功运行hello.golaunch.jsonhello.go

package main

import "fmt"

func main() {
    fmt.Println("Haiii")
}
钻研

评论

1赞 JimB 1/18/2023
请不要发布文字图片。Go 的版本很好,我会确保你安装了最新的 dlv 和任何其他工具。

答:

0赞 Calvin 1/19/2023 #1

我尝试将 go 版本和 delve 版本更改为与工作设备上的版本相同,F5 现在成功运行。我不知道是什么原因造成的

PS W:\workS\gqlusers> go version
go version go1.19.2 windows/amd64
PS W:\workS\gqlusers> dlv version
Delve Debugger
Version: 1.9.1
Build: $Id: d81b9fd12bfa603f3cf7a4bc842398bd61c42940 $