rules_js icon indicating copy to clipboard operation
rules_js copied to clipboard

Target 'constraints' not declared in package ''

Open BoopBoopBeepBoop opened this issue 3 years ago • 8 comments

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

BoopBoopBeepBoop avatar Oct 01 '22 11:10 BoopBoopBeepBoop

Oops, another consequence of trying to correctly identify Windows builds 😔

alexeagle avatar Oct 01 '22 18:10 alexeagle

Ah yeah that's another data point in case it helps - I'm running on arch linux.

BoopBoopBeepBoop avatar Oct 02 '22 01:10 BoopBoopBeepBoop

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",
)

gregmagolan avatar Oct 02 '22 14:10 gregmagolan

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

gregmagolan avatar Oct 02 '22 14:10 gregmagolan

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?

gregmagolan avatar Oct 03 '22 23:10 gregmagolan

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.

Silic0nS0ldier avatar Oct 05 '22 09:10 Silic0nS0ldier

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.

gregmagolan avatar Oct 05 '22 15:10 gregmagolan

@BoopBoopBeepBoop Can we close this issue?

cgrindel avatar Oct 14 '22 17:10 cgrindel

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

gregmagolan avatar Jan 13 '23 05:01 gregmagolan