0
0

Go | module declares its path as: <package-name> but was required as: <full-path>

Last updated at Posted at 2024-08-31

自分でCLIツールを作成してリリースしたが利用側でパッケージを取得しようとしたらエラーが発生したのでその時の対応のメモ。

結論

まずは結論から。

提供しているmodule名を変更した上で再リリース(自分の場合はタグの変更で発火するGHAで再リリース)

go.mod
- module gen-slice-accessor
+ module github.com/snamiki1212/gen-slice-accessor

リポジトリ・モジュール名を変えたので読み替えてください

-gen-slice-accessor
+go-gen-slice-accessors

発生していたエラー

  • パッケージ/リポジトリ名: gen-slice-accessor
  • GitHub アカウント名: snamiki1212
$ go install github.com/snamiki1212/gen-slice-accessor@latest
go: github.com/snamiki1212/gen-slice-accessor@latest: version constraints conflict:
	github.com/snamiki1212/gen-slice-accessor@v0.0.1: parsing go.mod:
	module declares its path as: gen-slice-accessor
	        but was required as: github.com/snamiki1212/gen-slice-accessor

結果

$ go install github.com/snamiki1212/gen-slice-accessor@latest
go: downloading github.com/snamiki1212/gen-slice-accessor v0.0.2

これで取得できるようになった

Appendix1. go:generate

コード生成を行うためのCLIを作成していたので、go:generate 側でのコマンドとしては下記のようにすればinstallを明示する必要がない

User.go
//go:generate go run -mod=mod github.com/snamiki1212/gen-slice-accessor@v0 --flag1=hoge
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0