debuggoMajor
How to fix parsing go.mod module declares its path as "x" but was required as "y"
Viewed 0 times
fixhowmoduledeclaresparsingmoditsbutpathrequired
Problem
I am working on a go project, which has a dependency on
But I keep getting this error:
Even when I run
What could I be doing wrong?
original-project. I now want to change the behavior in this project by modifying original-project. So I cloned github.com/y/original-project to github.com/x/my-version and replaced all occurrence of github.com/y/original-project with github.com/x/my-version (including in mod.go).But I keep getting this error:
go: github.com/x/my-version@v0.5.2: parsing go.mod:
module declares its path as: github.com/y/original-project
but was required as: github.com/x/my-versionEven when I run
go get -u -v -f all or github.com/x/my-versionWhat could I be doing wrong?
Solution
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-versionCode Snippets
replace github.com/y/original-project => /path/to/x/my-versionContext
Stack Overflow Q#61311436, score: 61
Revisions (0)
No revisions yet.