rules_js
rules_js copied to clipboard
Target 'constraints' not declared in package ''
Attempting to follow documentation to get started, I get the following failure on all versions later than 1.1.2
$ bazel fetch @npm//...
ERROR: /home/link/.cache/bazel/_bazel_link/d308e257cb21b18567ce974a260243dd/external/aspect_bazel_lib/lib/private/BUILD.bazel:24:12: no such target '@local_config_platform//:constraints': target 'constraints' not declared in package '' defined by /home/link/.cache/bazel/_bazel_link/d308e257cb21b18567ce974a260243dd/external/local_config_platform/BUILD.bazel and referenced by '@aspect_bazel_lib//lib/private:platform_utils'
ERROR: /home/link/.cache/bazel/_bazel_link/d308e257cb21b18567ce974a260243dd/external/aspect_bazel_lib/lib/private/BUILD.bazel:24:12: no such target '@local_config_platform//:constraints': target 'constraints' not declared in package '' defined by /home/link/.cache/bazel/_bazel_link/d308e257cb21b18567ce974a260243dd/external/local_config_platform/BUILD.bazel and referenced by '@aspect_bazel_lib//lib/private:platform_utils'
ERROR: Evaluation of query "deps(@npm//...)" failed: errors were encountered while computing transitive closure
$ bazel version
Build label: 5.1.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Apr 20 12:37:18 2022 (1650458238)
Build timestamp: 1650458238
Build timestamp as int: 1650458238
Oops, another consequence of trying to correctly identify Windows builds 😔
Ah yeah that's another data point in case it helps - I'm running on arch linux.
This was an issue introduced in bazel-lib recently (a rules_js dependency). It should be resolved with bazel-lib v1.12.1. Can you try adding this to the top of your WORKSPACE file?
http_archive(
name = "aspect_bazel_lib",
sha256 = "79381b0975ba7d2d5653239e5bab12cf54d89b10217fe771b8edd95047a2e44b",
strip_prefix = "bazel-lib-1.12.1",
url = "https://github.com/aspect-build/bazel-lib/archive/refs/tags/v1.12.1.tar.gz",
)
I'll cut a new rules_js release with this dependency updated later today but you should be able to work-around by pulling in the latest bazel-lib before calling rules_js_dependencies
Cut https://github.com/aspect-build/rules_js/releases/tag/v1.4.0 which updates the dependency on aspect_bazel_lib to latest. Can you please try that release to see if it resolves your issue?
Hit this issue on v1.4.0, got around it for the moment by adding the following to WORKSPACE.bazel.
load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "register_jq_toolchains")
aspect_bazel_lib_dependencies(override_local_config_platform = True)
This is present in the Rules JS WORKSPACE file and is hinted at as being needed in aspect_bazel_lib/lib/private/BUILD.bazel.
It seems you're getting an older version of aspect_bazel_lib in your WORKSPACE; perhaps somewhere before you call rules_js_dependencies ?
The fix that is in @aspect_bazel_lib v1.12.1 was to isolate the dependency on @local_config_platform//:constraints to aspect_bazel_lib/lib/private/docs/BUILD.bazel since it is only needed for stardoc bzl_library targets in the repo and not by users. aspect_bazel_lib/lib/private/BUILD.bazel no longer has the reference at HEAD: https://github.com/aspect-build/bazel-lib/blob/main/lib/private/BUILD.bazel.
@BoopBoopBeepBoop Can we close this issue?
This should no longer be an issue with Bazel 6 since @local_config_platform now exports constraints.bzl and bazel-lib uses:
bzl_library(
name = "local_config_platform_constraints",
srcs = ["@local_config_platform//:constraints.bzl"],
visibility = ["//visibility:public"],
)
for older versions of Bazel you'd still need aspect_bazel_lib_dependencies(override_local_config_platform = True) to get this export but that should only be needed downstream if you are depending on bzl_library targets from bazel-lib that are tucked away in lib/private/docs/BUILD.bazel so the dep on @local_config_platform//:constraints.bzl doesn't leak through the lib/private/BUILD.bazel package