-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: "package … is not in GOROOT" is confusing in module mode when the package would exist in GOPATH mode #38812
Comments
The package path Note that the location of the |
Perhaps there is something we could do based on the fact that the package would exist if it were loaded in GOPATH mode, but I'm not sure exactly how we would phrase that. |
There are a couple checks for Seems pretty broad though, and I expect it would break a lot of tool tests. |
Maybe? But tool tests in module mode need a So if the check only happens in module mode, it should not actually affect any tests! 😅 |
why is my error like this "is not in GOROOT"? on windows10 |
Just check for correct imports in go files. External import file need to start with the module name, which u can find in go.mod under root dir. For example u have the structure like RootDir/main.go, RootDir/go.mod, RootDir/configs/constants.go and u want to import RootDir/configs/constants.go in RootDir/main.go. Check the name of module in go.mod. If there is "module example.com/RootDir, then yours import look like "import example.com/RootDir/configs" not like "RootDir/configs". |
I had a similar problem |
This is in the Go 1.18 milestone. Is it likely to happen for 1.18? Thanks. |
@bcmils This is in the 1.18 milestone; time to move to 1.19? |
Type these two commands in your terminal to resolve the issue go env -w GO111MODULE=off set GOPATH=D:\go |
In my case, the first command line resolve my problem. Thanks :). Could you explain me what do that line? |
Gracias, lo corregi con el comando: go env -w GO111MODULE=off |
Had the same issue but it was due to not having the go module at root. What I was trying to accomplish was to execute the commands in a Cobra CLI app This is what I did to fix it:
|
in 1.19.1,I met this problem,and I solve it by keeping package name and corresponding folder name the same。But why can do like this? |
Thank you for the hint! I've solved the issue by keeping the package name and corresponding folder name the same. |
Thanks for your workable approach which saves my day! |
What do you think if we return something like this?
|
Change https://go.dev/cl/543275 mentions this issue: |
@quantonganh, the error should not suggest running in Generally the best solution is to update the program and its dependencies to use modules with module-appropriate paths, and then use the |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
If a parent folder contained a
go.mod
this overrides the GOPATH setting and there is no clear indication this is happening.lets say the following exists in the file system
and say you create a folder like
and you export the GOPATH to point to your project
You will get an error like
And much time and head bashing will occur because you dont realize that go is using the
/work/go.mod
and overrides yourGOPATH
that you defined. This behavior is different then go 1.12 as well (it compiles without issue) so that adds to the confusion. (To be fair... I am totally guilty as sin for my own nasty creation, but there should be a better way of pointing out the root cause.)What did you expect to see?
It would be great to see some reference to the
go.mod
file in the error message and not theGOROOT
.Or even more directly
I agree the former error is not wrong, but it is pointing in the wrong direction
What did you see instead?
The text was updated successfully, but these errors were encountered: