Could not import github.com/u-root/u-root/pkg/curl

Hi

When trying to import the following I receive an error on the module for github. This is also the same for many modules containing github.

import (

"math"

"github.com/u-root/u-root/pkg/curl"

)

could not import github.com/u-root/u-root/pkg/curl (cannot find package “github.com/u-root/u-root/pkg/curl” in GOROOT)compilerBrokenImport

I have tired quite a few fixes, but still unable to get this to work. I do not have a go.mod file set.

Current GO ENV

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\matt\AppData\Local\go-build
set GOENV=C:\Users\matt\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\matt\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\matt\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.23.1
set GODEBUG=
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\matt\AppData\Roaming\go\telemetry
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\MATT~1\AppData\Local\Temp\go-build4268344471=/tmp/go-build -gno-record-gcc-switches

Any help would be much appreciated.

Thanks

Matt

Please check if there is any import reference package from GOPATH.
(Why not use go.mod? It’s a convenience thing.)

Hi

This is what is in my GOPATH

Sorry I am quite new to GO.

Using a GO.MOD would i just create and put the module path in?

Thanks

Matt

Newbie? Then use go.mod!
Execute the following commands:
cd (your project path)
go mod init (your project domain name, such as github.com/xxx/yyyy, this domain name is generally the accessible path of the project, if your project wants to be referenced; of course, you can fill in something casually)
go mod tidy

Thanks for the feedback. I will give it a go and update

Hi I have tried as suggested but still not working. Have attached screen shot with go.mod file and output

import cycle not allowed

It’s not the mod’s fault, it’s your code’s fault.
Check your code for package cycles.
If you don’t know what a package cycle is, then what you should do is consult a book.

Also, according to your mod file, it looks like the project you’re working on is github.com/u-root/u-root/pkg/curl. Why does import github.com/u-root/u-root/pkg/curl happen?

It looks like you initialized your module with the name of the module you want to import. Since you initialized the module with the module you are trying to import, the error is saying “I can’t import myself” more or less. Try go mod init example.com/matt/testing.

Here’s an example importing that module on the playground that works fine: