Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error step "go build" #741

Open
albrivas opened this issue Dec 14, 2020 · 1 comment
Open

Error step "go build" #741

albrivas opened this issue Dec 14, 2020 · 1 comment

Comments

@albrivas
Copy link

When I execute the "go build" command, I get the following error in the terminal:

./libretaxi.go:43:14: cannot use bot (type *"github.com/go-telegram-bot-api/telegram-bot-api".BotAPI) as type *"libretaxi/vendor/github.com/go-telegram-bot-api/telegram-bot-api".BotAPI in assignment ./libretaxi.go:58:42: cannot use u (type "github.com/go-telegram-bot-api/telegram-bot-api".UpdateConfig) as type "libretaxi/vendor/github.com/go-telegram-bot-api/telegram-bot-api".UpdateConfig in argument to context.Bot.GetUpdatesChan ./libretaxi.go:79:56: cannot use "github.com/go-telegram-bot-api/telegram-bot-api".NewCallback(cb.ID, "👌 OK") (type "github.com/go-telegram-bot-api/telegram-bot-api".CallbackConfig) as type "libretaxi/vendor/github.com/go-telegram-bot-api/telegram-bot-api".CallbackConfig in argument to context.Bot.AnswerCallbackQuery ./libretaxi.go:84:30: cannot use removeButton (type "github.com/go-telegram-bot-api/telegram-bot-api".EditMessageReplyMarkupConfig) as type "libretaxi/vendor/github.com/go-telegram-bot-api/telegram-bot-api".Chattable in argument to context.Bot.Send: "github.com/go-telegram-bot-api/telegram-bot-api".EditMessageReplyMarkupConfig does not implement "libretaxi/vendor/github.com/go-telegram-bot-api/telegram-bot-api".Chattable (missing "libretaxi/vendor/github.com/go-telegram-bot-api/telegram-bot-api".method method) have "github.com/go-telegram-bot-api/telegram-bot-api".method() string want "libretaxi/vendor/github.com/go-telegram-bot-api/telegram-bot-api".method() string ./libretaxi.go:149:5: cannot use msg (type "github.com/go-telegram-bot-api/telegram-bot-api".MessageConfig) as type "libretaxi/vendor/github.com/go-telegram-bot-api/telegram-bot-api".MessageConfig in field value

Can you help me?

Thanks

@umamaheshwar3528
Copy link

The error messages you're seeing indicate a common issue in Go projects related to package management and import paths, especially when vendoring is involved. Your project is trying to use two versions of the telegram-bot-api library: one from the standard Go package path (github.com/go-telegram-bot-api/telegram-bot-api) and one from your project's vendor directory (libretaxi/vendor/github.com/go-telegram-bot-api/telegram-bot-api). Go treats these as different packages, even though they might be the same code, which is why you're seeing type mismatch errors.

Here’s how you can resolve this issue:

  1. Consolidate the Imports:
    Ensure that you consistently use either the vendored package or the one from your GOPATH/GOMODULE across your entire project. It’s crucial to not mix imports from these two sources as they are treated as distinct by the Go compiler.

  2. Using Go Modules (Recommended if you are not already using it):
    If your project is not already using Go Modules, I recommend transitioning to it, as it effectively handles package versions and dependencies, and also eliminates the need for a vendor directory unless explicitly desired.

    • Initialize modules in your project (if not already done):
      go mod init <module_name>
    • Add your dependencies:
      go mod tidy
    • Build your project:
      go build
  3. If Continuing with Vendoring:

    • Make sure all your code imports the library from the vendor directory. Update all import statements from:
      import "github.com/go-telegram-bot-api/telegram-bot-api"
      to
      import "libretaxi/vendor/github.com/go-telegram-bot-api/telegram-bot-api"
    • Run the build again to see if the issue persists.
  4. Check for Updates:
    Sometimes, these issues can be due to bugs or incompatibilities in the libraries themselves, which might be fixed in newer versions. Check if there are updates available for telegram-bot-api and consider upgrading.

  5. Revendor Dependencies:
    If you decide to stick with vendoring and you've made changes to your import paths or updated your dependencies, you might need to revendor your dependencies:

    • Remove the existing vendor directory:
      rm -rf vendor/
    • Revendor dependencies:
      go mod vendor
  6. Clean and Rebuild:
    Sometimes stray files or incorrect states cached by the Go build system can cause issues:

    go clean -modcache
    go build

Start with these steps, and they should help you resolve the import conflicts in your Go project. If the issue persists, it might be useful to check if there are any specific configurations in your environment that are influencing how packages are imported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants