How to fix parsing go.mod module declares its path as "x" but was required as "y"

Solution 1:

I had similar issue. I ended up removing the go.mod file in the project I was trying to import and running go mod init ... again. It fixed it.

Also, run go clean -modcache where you are importing.

Then try to go get ... your package.

Solution 2:

I think the problem comes from the fact that the go.mod of your cloned version of original-project still says module github.com/y/original-project. You should use the go.mod replace directive. It is meant for cases like yours exactly.

replace github.com/y/original-project => /path/to/x/my-version