Bazel build: No repository visible as '@rules_go'
The following bazel build error was received when trying to update from github.com/open-policy-agent/opa v0.70.0 to github.com/open-policy-agent/opa v1.8.0. It targets a Go Monorepo with Bazel + Gazelle + rules_go (Bzlmod enabled).
ERROR: error loading package '@@gazelle~~go_deps~com_github_lestrrat_go_jwx_v3//jwk': Unable to find package for @@[unknown repo 'rules_go' requested from @@gazelle~~go_deps~com_github_lestrrat_go_jwx_v3 (did you mean 'rules_cc'?)]//go:def.bzl: The repository '@@[unknown repo 'rules_go' requested from @@gazelle~~go_deps~com_github_lestrrat_go_jwx_v3 (did you mean 'rules_cc'?)]' could not be resolved: No repository visible as '@rules_go' from repository '@@gazelle~~go_deps~com_github_lestrrat_go_jwx_v3'. ERROR: /home/lukas/.cache/bazel/_bazel_lukas/900f15fa8982dac93cf1f3f7d5adf494/external/gazelle~~go_deps~com_github_open_policy_agent_opa/v1/topdown/BUILD.bazel:3:11: error loading package '@@gazelle~~go_deps~com_github_lestrrat_go_jwx_v3//jwk': Unable to find package for @@[unknown repo 'rules_go' requested from @@gazelle~~go_deps~com_github_lestrrat_go_jwx_v3 (did you mean 'rules_cc'?)]//go:def.bzl: The repository '@@[unknown repo 'rules_go' requested from @@gazelle~~go_deps~com_github_lestrrat_go_jwx_v3 (did you mean 'rules_cc'?)]' could not be resolved: No repository visible as '@rules_go' from repository '@@gazelle~~go_deps~com_github_lestrrat_go_jwx_v3'. and referenced by '@@gazelle~~go_deps~com_github_open_policy_agent_opa//v1/topdown:topdown' ERROR: Analysis of target '//bzlmod:go_default_library' failed; build aborted: Analysis failed INFO: Elapsed time: 2.102s, Critical Path: 0.04s INFO: 1 process: 1 internal. ERROR: Build did NOT complete successfully
A minimal example is given in this repository.
@lschlacher any chance you've found a solution for this? I've run into the same problem.
@lschlacher any chance you've found a solution for this? I've run into the same problem.
@rossdylan Sadly, I haven’t found a solution yet, so I’ve downgraded back to v1.7.1 for the time being.
Could you try adding an override with build_file_generation = "clean" (example: https://github.com/bazel-contrib/bazel-gazelle/blob/b13c1573c378bb3dd9b9de1397db89d0392f8e72/tests/bcr/go_mod/MODULE.bazel#L162)?
I found a pretty hacky work around which is to depend on the bazel module from github.com/lestrrat-go/jwx instead of the go module. It required some extra patches due to problems in a few build files but it was building.
I'll give the build_file_generation = "clean" option a go as well
@fmeum yep that fixed it
If you have the time, could you add this module to https://github.com/bazel-contrib/bazel-gazelle/blob/b13c1573c378bb3dd9b9de1397db89d0392f8e72/internal/bzlmod/default_gazelle_overrides.bzl#L17 with mode clean?
@fmeum Fixed it for me too, thank you so much. I will add it to the suggested module as soon as I can.
For all others having this issue: To make it build you will also need bazel_dep(name = "gazelle", version = "0.43.0") with version >= "0.43.0"