{"id":319,"hash":"0885bc1ce5ac2a5b1e4a7bd76f0d7800234240a4f981821190eb00240f06de4f","pattern":"go mod: cannot find module providing package","full_message":"I am creating a go project with version 1.12.1.\nIf I run GOPATH=\"$(pwd)/vendor:$(pwd)\" GOBIN=\"$(pwd)/bin\" go clean I get the following error:\n\ncan't load package: package github.com/marvincaspar/go-example: unknown import path \"github.com/marvincaspar/go-example\": cannot find module providing package github.com/marvincaspar/go-example\n\nThis is only for go clean, go run or go build works fine.\n\nHere is the folder structure of main code:\n\n.\n├── Makefile\n├── cmd\n│   └── server\n│       └── main.go\n├── go.mod\n├── go.sum\n└── pkg\n    └── storage\n        └── mysql\n            └── storage.go\n\nHere is how the go.mod file looks like:\n\nmodule github.com/marvincaspar/go-example\ngo 1.12\n\nrequire (\n    github.com/go-sql-driver/mysql v1.4.1\n)\n\nAnd finally the main.go file:\n\npackage main\n\nimport (\n    \"fmt\"\n    \"os\"\n\n    \"github.com/marvincaspar/go-example/pkg/storage/mysql\"\n)\n\nfunc main() {\n    if err := run(); err != nil {\n        fmt.Fprintf(os.Stderr, \"%v\", err)\n        os.Exit(1)\n    }\n}\n\nfunc run() error {\n    // init storage\n    s := mysql.NewStorage()\n    // do some other stuff...\n}\n\nAny ideas what I am doing wrong?","ecosystem":"go","package_name":"go-modules","package_version":null,"solution":"Go build/install is trying to find main package in your root directory, it is not checking sub-directories (cmd/server) in your case. Hence you are getting package not found error.\n\nTo properly build your code, you can run:\n\ngo build github.com/marvincaspar/go-example/cmd/server\n\nSimilarly, to run your project, you will have to provide module-name/main-package-path: \n\ngo run github.com/marvincaspar/go-example/cmd/server\n\nGo clean can be executed in same way, by providing module-name/path-with-main-package\n\ngo clean github.com/marvincaspar/go-example/cmd/server\n\nor\n\nGOPATH=\"$(pwd)/vendor:$(pwd)\" GOBIN=\"$(pwd)/bin\" go clean github.com/marvincaspar/go-example/cmd/server \n\nHowever, as per https://blog.learngoprogramming.com/code-organization-tips-with-packages-d30de0d11f46, just put your source files into your project’s root. It’s better that way.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/55631569/go-mod-cannot-find-module-providing-package","votes":70,"created_at":"2026-04-19T04:41:53.387981+00:00","updated_at":"2026-04-19T04:52:39.800664+00:00"}