rules_js icon indicating copy to clipboard operation
rules_js copied to clipboard

Error message not helpful when virtual store not linked

Open kylepl opened this issue 9 months ago • 2 comments

What happened?

Hey,

I've been trying out the new ts_proto_library (very excited to use it), and quite likely I'm missing something, but figured I'd file a bug to either help others if I figure it out myself, or if someone sees an obvious problem. It's worth noting I'm not too familiar with NPM, so I did not have an existing lock file, thus bootstrapping just to support ts_proto_library.

So essentially I have:

load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@aspect_rules_ts//ts:proto.bzl", "ts_proto_library")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(name = "node_modules")

proto_library(
    name = "foo_proto",
    srcs = [":foo.proto"],
)

ts_proto_library(
    name = "foo_ts_proto",
    node_modules = ":node_modules",
    proto = ":foo_proto",
)

And I get error:

no such target '//:.aspect_rules_js/node_modules/@[email protected]': target '.aspect_rules_js/node_modules/@[email protected]' not declared in package '' defined by /myrepo/BUILD (Tip: use `query "//:*"` to see all the targets in that package) and referenced by '//my_directory:node_modules/@bufbuild/protobuf'

I have a my_directory/package.json, like in the example (with a pnpm_workspace.yaml that refers to it):

{
  "dependencies": {
    "@bufbuild/protobuf": "1.3.0"
  },
  "devDependencies": {
    "@bufbuild/protoc-gen-es": "1.3.0",
    "@bufbuild/protoc-gen-connect-es": "0.12.0"
  },
  "type": "module"
}

and have generated the lock file, referencing it with:

npm.npm_translate_lock(
    name = "npm",
    # Regenerate dependencies with `bazel run -- @pnpm//:pnpm --dir $PWD install --lockfile-only`.
    pnpm_lock = "//:pnpm-lock.yaml")

Version

Development (host) and target OS/architectures: Linux

Output of bazel --version: bazel 6.0.0

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

bazel_dep(name = "aspect_rules_ts", version = "2.0.0-rc1")
bazel_dep(name = "aspect_rules_js", version = "1.32.2")

How to reproduce

No response

Any other information?

Using bzlmod.

kylepl avatar Sep 13 '23 13:09 kylepl

This appears to be fixed in my case, in addition to having npm_link_all_packages in my_directory/BUILD, also having it in the root BUILD file, i.e. adding:

load("@npm//:defs.bzl", "npm_link_all_packages")

npm_link_all_packages(
    name = "node_modules",
)

It only compiles if both are defined. I don't see this in the example, so maybe I'm doing something wrong?

kylepl avatar Sep 13 '23 14:09 kylepl

The example does link the root - it just has the root in a subpackage of the workspace. https://github.com/aspect-build/rules_ts/blob/main/examples/BUILD.bazel#L35 is next to the pnpm-lock.yaml

This is really a rules_js issue, that the error message isn't very helpful when the .aspect_rules_js virtual store wasn't created.

alexeagle avatar Sep 18 '23 19:09 alexeagle