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

[Bug]: Unable to use js_binary in other workspaces in bazel 7 #1421

Open
calliecameron opened this issue Dec 31, 2023 · 1 comment
Open

[Bug]: Unable to use js_binary in other workspaces in bazel 7 #1421

calliecameron opened this issue Dec 31, 2023 · 1 comment
Labels
untriaged Requires traige

Comments

@calliecameron
Copy link

In one module, I define a js_binary rule (using markdownlint from npm). I can run this fine in this module.

I make another module, and depend on the first module using local_path_override. If any targets in the second module refer to the js_binary from the first module, I get an error saying the repository could not be resolved.

Development (host) and target OS/architectures: Ubuntu 22.04 x86_64

Output of bazel --version: 7.0.0

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: 1.34.1

Language(s) and/or frameworks involved: js

Minimal example:

$ \ls -AR 
.:
.bazelversion  BUILD  MODULE.bazel  WORKSPACE  other/  package.json

./other:
BUILD  MODULE.bazel  WORKSPACE

$ cat .bazelversion
7.0.0

$ cat BUILD
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//:markdownlint-cli/package_json.bzl", markdownlint = "bin")

npm_link_all_packages()

markdownlint.markdownlint_binary(
    name = "markdownlint",
)

$ cat MODULE.bazel
module(
    name = "md-test",
    version = "0.0.0",
)

bazel_dep(name = "aspect_rules_js", version = "1.34.1")

bazel_dep(name = "rules_nodejs", version = "5.8.2")

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")
npm.npm_translate_lock(
    name = "npm",
    pnpm_lock = "//:pnpm-lock.yaml",
)
use_repo(npm, "npm")

pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm")
use_repo(pnpm, "pnpm")

$ cat WORKSPACE

$ cat package.json
{
    "dependencies": {
        "markdownlint-cli": "0.38.0"
    },
    "pnpm": {
        "packageExtensions": {
            "markdownlint-cli": {
                "dependencies": {
                    "deep-extend": "*"
                }
            }
        }
    }
}

$ cat other/BUILD
alias(
    name = "markdownlint",
    actual = "@md-test//:markdownlint",
)

$ cat other/MODULE.bazel
module(
    name = "other",
    version = "0.0.0",
)

bazel_dep(
    name = "md-test",
    version = "0.0.0",
)

local_path_override(
    module_name = "md-test",
    path = "..",
)

$ cat other/WORKSPACE

Initialise with:

$ bazel run -- @pnpm//:pnpm --dir $PWD install --lockfile-only

Then in the first module, the following works:

$ bazel run :markdownlint -- --version
0.38.0

But trying to run the target in the second module, that references the first, doesn't work:

$ cd other
$ bazel run :markdownlint -- --version
Starting local Bazel server and connecting to it...
bazel: Entering directory `/home/callie/.cache/bazel/_bazel_callie/5b831d15f550aa9c312e3eef2fd97503/execroot/_main/'
INFO: Repository rules_nodejs~5.8.2~node~nodejs_linux_amd64 instantiated at:
  <builtin>: in <toplevel>
Repository rule node_repositories defined at:
  /home/callie/.cache/bazel/_bazel_callie/5b831d15f550aa9c312e3eef2fd97503/external/rules_nodejs~5.8.2/nodejs/repositories.bzl:374:36: in <toplevel>
ERROR: no such package '@@[unknown repo 'md-test~override' requested from @@md-test~override]//': The repository '@@[unknown repo 'md-test~override' requested from @@md-test~override]' could not be resolved: No repository visible as '@md-test~override' from repository '@@md-test~override'
ERROR: /home/callie/.cache/bazel/_bazel_callie/5b831d15f550aa9c312e3eef2fd97503/external/md-test~override/BUILD:6:33: no such package '@@[unknown repo 'md-test~override' requested from @@md-test~override]//': The repository '@@[unknown repo 'md-test~override' requested from @@md-test~override]' could not be resolved: No repository visible as '@md-test~override' from repository '@@md-test~override' and referenced by '@@md-test~override//:markdownlint'
bazel: Leaving directory `/home/callie/.cache/bazel/_bazel_callie/5b831d15f550aa9c312e3eef2fd97503/execroot/_main/'
ERROR: Analysis of target '//:markdownlint' failed; build aborted: Analysis failed
INFO: Elapsed time: 6.153s, Critical Path: 0.05s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target
@github-actions github-actions bot added the untriaged Requires traige label Dec 31, 2023
@tgeng
Copy link

tgeng commented Sep 14, 2024

I am hitting the same problem. Any way to resolve this? The rationale is that we would like to embed some tools based on rules_js for an internal tooling module that will be shared among a few other Bazel repos. Currently we have to work around the problem by setting up the executable in all consuming repos and pass a label pointing to the tools we need when registering the tooling module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged Requires traige
Projects
Status: No status
Development

No branches or pull requests

2 participants