"module declares its path as X but was required as Y" error occurs because your code is importing a module using a path different from the one declared in its go.mod file. Ensure your import statement matches the module path exactly as defined in the dependency's go.mod file, and run go mod tidy to update your local go.mod and go.sum files.
go mod tidy
If the error persists, verify that you are not importing a local copy of the module with a different path than the remote version, and ensure your go.mod file's require directive matches the correct module path.