Search code examples
gogo-modules

Golang upgrading incompatible modules


So I have a version of chi module that is incompatible and I can't upgrade it using go get <package-name> it only upgrades to the latest incompatible version while there are quite a few more versions released. I need some functionalities from the new version library which the incompatible one does not have. The go.mod file incompatible library looks like this: github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs=

I tried deleting my modules and running go mod init again using, but it still gives me the incompatible version. I think this might be because my project is connected to my bitbucket repository. I also tried deleting the module from the go environment and downloading it again, but had the same outcome.

How can I overcome this problem? Does anyone have any ideas? Maybe I have to manually clear the modules from my repository as well and then try to init them again?

Thank you.


Solution

  • When the version you want starts to get compatible with Go modules, you have to go get the dependency and import the packages in source files with the correct versioned import path, as declared in their go.mod file.

    Chi's current go.mod on master branch declares its module as:

    module github.com/go-chi/chi/v5
    

    So:

    go get github.com/go-chi/chi/v5

    And in source files:

    import "github.com/go-chi/chi/v5"
    
    func main() {
        r := chi.NewRouter()
        // ...
    }