{"id":320,"hash":"f0cd14bcd5f35b132554cdb20a3673a4f486aecf2b5e61bd9d78c8efbca4ffa0","pattern":"Go get cannot find local packages when using multiple modules in a repo","full_message":"I'm having issues with go's new module system, as I'd like to define a local module and import it in the main program. The local package resides in a folder of the main package/root folder. Imagine the following project structure outside the $GOPATH.\n\nProject structure\n\n./main.go\n\npackage main\n\nimport \"fmt\"\nimport \"example.com/localModule/model\"\n\nfunc main() {\n    var p = model.Person{name: \"Dieter\", age:25}\n    fmt.Printf(\"Hello %s\\n\", p.name)\n}\n\n./model/person.go\n\npackage model\n\ntype Person struct {\n    name string\n    age int\n}\n\nIn the root folder I initialized a module by calling\n\ngo mod init example.com/localModule\n\nIn the model/ folder I then initialized the submodule by calling\n\ngo mod init example.com/localModule/model\n\nThe error\n\nIn the root folder calling the following commands fail. \n\n$ go get\ngo build example.com/localModule/model: no Go files in\n\n$ go build\nmain.go:4:8: unknown import path \"example.com/localModule/model\": cannot find module providing package example.com/localModule/model\n\nThe error message for go get is cut off, I din't parse it wrongly.\n\nI do not plan on pushing the module to a server and and just needed a way of referencing the local package model, so I chose example.com/localModule/ and example.com/localModule/model respectively.\n\nI'm using go1.11 darwin/amd64 on a Macbook running MacOS 10.13.6.","ecosystem":"go","package_name":"module","package_version":null,"solution":"You can have local \"sub\" modules like you ask for by adding a require statement and a matching replace statement with a relative file path in go.mod.\n\nIn the \"root\" ./go.mod:\n\nmodule example.com/localModule\n\nrequire example.com/localModule/model v0.0.0\n\nreplace example.com/localModule/model v0.0.0 => ./model","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/52079662/go-get-cannot-find-local-packages-when-using-multiple-modules-in-a-repo","votes":48,"created_at":"2026-04-19T04:41:53.389346+00:00","updated_at":"2026-04-19T04:52:39.801996+00:00"}