[Q]: How to use rules_ts within local bazel_dep ?
What happened?
I have root workspace
root MODULE.bazel
bazel_dep(name = "submodule")
local_path_override(
module_name = "submodule",
path = "./submodule",
)
bazel_dep(name = "aspect_rules_ts", version = "1.4.5")
rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext")
rules_ts_ext.deps()
use_repo(rules_ts_ext, "npm_typescript", dev_dependency = True)
and submodule MODULE.bazel
module(name = "submodule")
bazel_dep(name = "aspect_rules_ts", version = "1.4.5")
rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext")
rules_ts_ext.deps()
use_repo(rules_ts_ext, "npm_typescript")
I cant build root WS
% bazel mod deps --lockfile_mode=update
ERROR: Traceback (most recent call last):
File "/private/var/tmp/_bazel_farcop/19c93210ef2d95dd4248c025caf8c584/external/aspect_rules_ts~1.4.5/ts/extensions.bzl", line 14, column 29, in _extension_impl
npm_dependencies(ts_version = ts_version, ts_version_from = attr.ts_version_from, ts_integrity = attr.ts_integrity)
File "/private/var/tmp/_bazel_farcop/19c93210ef2d95dd4248c025caf8c584/external/aspect_rules_ts~1.4.5/ts/private/npm_repositories.bzl", line 76, column 10, in npm_dependencies
maybe(
File "/private/var/tmp/_bazel_farcop/19c93210ef2d95dd4248c025caf8c584/external/bazel_tools/tools/build_defs/repo/utils.bzl", line 233, column 18, in maybe
repo_rule(name = name, **kwargs)
Error in repository_rule: A repo named npm_typescript is already generated by this module extension at /private/var/tmp/_bazel_farcop/19c93210ef2d95dd4248c025caf8c584/external/bazel_tools/tools/build_defs/repo/utils.bzl:233:18
ERROR: error evaluating module extension ext in @aspect_rules_ts~1.4.5//ts:extensions.bzl. Type 'bazel help mod' for syntax and help.
checking cached actions
if I set dev_dependency = True at submodule then it unable to build submodule from root module.
Version
bazel 6.4.0 "aspect_rules_ts", version = "1.4.5"
How to reproduce
See above
Any other information?
No response
I'm having a similar problem with local repositories. When trying to build a ts_project rule from a nested repository from the root repository I'm asked the following:
You must choose exactly one of the following flags:
1. To choose the faster performance put this in /.bazelrc:
# passes an argument `--skipLibCheck` to *every* spawn of tsc
build --@aspect_rules_ts//ts:skipLibCheck=always
fetch --@aspect_rules_ts//ts:skipLibCheck=always
query --@aspect_rules_ts//ts:skipLibCheck=always
2. To choose more correct typechecks, put this in /.bazelrc:
# honor the setting of `skipLibCheck` in the tsconfig.json file
build --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
fetch --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
query --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
##########################################################
Now if I add the mentioned flag:
(devbox) nix-shell-env ❯ bazel run --@aspect_rules_ts//ts:skipLibCheck=always //tools/bunq2ynab:kerk
ERROR: Skipping '@aspect_rules_ts//ts:skipLibCheck': No repository visible as '@aspect_rules_ts' from main repository
WARNING: Target pattern parsing failed.
ERROR: @aspect_rules_ts//ts:skipLibCheck :: Error loading option @aspect_rules_ts//ts:skipLibCheck: No repository visible as '@aspect_rules_ts' from main repository
Loading:
It complains because the main repository does not know about this flag, only the nested repository. I think the only way to get around this is to add the aspect_rules_ts as a direct dependency to the root repository, which I kinda don't want to do because the main repository does not have a direct dependency on this rule set.
sorry for the long delay in replying!
@farcop Could you publish a minimal repro of this, ideally as a red PR to rules_ts examples/ or e2e/ folder, but an empty github repo would work as well. That would save me time getting the failure into a local test fixture. I've never seen usage of Bazel nested modules like this, so I'm not surprised there's an issue. The hardcoded name at https://github.com/aspect-build/rules_ts/blob/main/ts/private/npm_repositories.bzl#L141 does mean the repository rule may only be called once.
@mvgijssel Your issue is different. Would you file separately please? I think there's a workaround where you make your own load("//ts/private:options.bzl", "options") like https://github.com/aspect-build/rules_ts/blob/main/ts/BUILD.bazel#L115-L121 and supply whatever values you like.