Skip to content

[Bug]: encounting error TS5058: The specified path does not exist: '**/tsconfig.json'. when working with ts_project #805

@samuelisch

Description

@samuelisch

What happened?

I noticed in a monorepo that tsconfig.json isn't getting detected by bazel, even though it successfully shows up in bazel-bin. The error details are:

sam@RANDOMNAME/ rbac % bazel build :tsc --verbose_failures --sandbox_debug                                                                  
Starting local Bazel server and connecting to it...
INFO: Analyzed target //rbac:tsc (51 packages loaded, 4715 targets configured).
INFO: Found 1 target...
ERROR: /Users/sam/7is/repo/rbac/BUILD:6:11: Transpiling & type-checking TypeScript project @//rbac:tsc [tsc -p rbac/tsconfig.json] failed: (Exit 1): sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_sam/1213a65374144926830e6c56ce40f316/sandbox/darwin-sandbox/5/execroot/small-repo && \
  exec env - \
    BAZEL_BINDIR=. \
    PATH=/Users/samuelchan/Library/Caches/bazelisk/downloads/sha256/c6b6dc17efcdf13fba484c6fe0b6c3361b888ae7b9573bc25a2dbe8c502448eb/bin:/opt/homebrew/bin:/opt/homebrew/bin:/Users/sam/.rbenv/shims:/Users/sam/.rbenv/bin:/Users/sam/.nvm/versions/node/v20.17.0/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/opt/homebrew/bin:/Users/sam/Library/pnpm:/Users/samuelchan/.rbenv/bin:/Users/sam/.nvm/versions/node/v20.17.0/bin:/Users/sam/.vscode/extensions/ms-python.debugpy-2025.6.0-darwin-arm64/bundled/scripts/noConfigScripts \
    TMPDIR=/var/folders/jn/222bt8f14ns215y43dbg7z_00000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_sam/1213a65374144926830e6c56ce40f316/sandbox/darwin-sandbox/5/sandbox.sb /var/tmp/_bazel_sam/install/4cce4079417824dc23315418e12c159b/process-wrapper '--timeout=0' '--kill_delay=15' '--stats=/private/var/tmp/_bazel_sam/1213a65374144926830e6c56ce40f316/sandbox/darwin-sandbox/5/stats.out' bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/npm_typescript/tsc_/tsc --outDir rbac/lib --declarationDir rbac/lib --project rbac/tsconfig.json --rootDir rbac)
error TS5058: The specified path does not exist: 'rbac/tsconfig.json'.
Target //rbac:tsc failed to build
INFO: Elapsed time: 8.703s, Critical Path: 1.95s
INFO: 11 processes: 7 internal, 4 local.
FAILED: Build did NOT complete successfully

and my defined target, within /rbac/BUILD

load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
    name = "tsc",
    srcs = glob([
        "src/**",
        "tsconfig.json",
    ]),
    declaration = True,
    validate = False,
    transpiler = 'tsc',
    tsconfig = "tsconfig.json",
    out_dir = "lib",
)

upon closer inspection, i see that the temporary directory /private/var/tmp/_bazel_sam/1213a65374144926830e6c56ce40f316/sandbox/darwin-sandbox/5/execroot/small-repo does not contain rbac/tsconfig, and only contains bazel-out. However, when checking with an example genrule to debug, i see that with genrule it exists

# genrule step
genrule(
    name = "debug-tsc",
    srcs = glob([
        "src/**",
        "tsconfig.json",
    ]),
    outs = ["debug.txt"],
    # This command runs inside the sandbox CWD (execroot/small-repo)
    cmd = """
        echo "--- Current Directory: $$(pwd) ---" > $@
        echo "\n--- Listing CWD Contents ---" >> $@
        ls -la >> $@
        echo "\n--- Listing ./rbac/ ---" >> $@
        ls -la ./rbac >> $@ || echo "*** ./rbac/ directory not found ***" >> $@
        echo "\n--- Listing ./rbac/tsconfig.json ---" >> $@
        ls -la ./rbac/tsconfig.json >> $@ || echo "*** ./rbac/tsconfig.json not found ***" >> $@
        echo "\n--- Done ---" >> $@
    """,
)
output to `bazel-bin`.
--- Current Directory: /private/var/tmp/_bazel_samuelchan/1213a65374144926830e6c56ce40f316/sandbox/darwin-sandbox/1/execroot/small-repo ---

--- Listing CWD Contents ---
total 0
drwxr-xr-x  5 sam  wheel  160 May  6 11:40 .
drwxr-xr-x  3 sam  wheel   96 May  6 11:40 ..
drwxr-xr-x  3 sam  wheel   96 May  6 11:40 bazel-out
drwxr-xr-x  3 sam  wheel   96 May  6 11:40 external
drwxr-xr-x  4 sam  wheel  128 May  6 11:40 rbac

--- Listing ./rbac/ ---
total 0
drwxr-xr-x  4 sam  wheel  128 May  6 11:40 .
drwxr-xr-x  5 sam  wheel  160 May  6 11:40 ..
drwxr-xr-x  4 sam  wheel  128 May  6 11:40 src
lrwxr-xr-x  1 sam  wheel  106 May  6 11:40 tsconfig.json -> /private/var/tmp/_bazel_sam/1213a65374144926830e6c56ce40f316/execroot/small-repo/rbac/tsconfig.json

--- Listing ./rbac/tsconfig.json ---
lrwxr-xr-x  1 sam  wheel  106 May  6 11:40 ./rbac/tsconfig.json -> /private/var/tmp/_bazel_sam/1213a65374144926830e6c56ce40f316/execroot/small-repo/rbac/tsconfig.json

--- Done ---

how can i solve this? why is it not appearing when i run ts_project with all ts files and tsconfig?

Version

Development (host) and target OS/architectures:

Output of bazel --version: bazel 6.5.0

WORKSPACE:

workspace(
    name = "small-repo",
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file", "http_jar")
# load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")

http_archive(
    name = "aspect_rules_ts",
    sha256 = "fa5659a511f236b1ae6112258bff602fa20a40324b282734c841bc1e857797f3",
    strip_prefix = "rules_ts-3.5.2",
    url = "https://github.com/aspect-build/rules_ts/releases/download/v3.5.2/rules_ts-v3.5.2.tar.gz",
)
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
rules_ts_dependencies(
    ts_version_from = "//rbac:package.json",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
rules_js_dependencies()

load("@aspect_rules_js//js:toolchains.bzl", "rules_js_register_toolchains")
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

rules_js_register_toolchains()
npm_translate_lock(
    name = "npm",
    pnpm_lock = "//rbac:pnpm-lock.yaml",
)
load("@npm//:repositories.bzl", "npm_repositories")
npm_repositories()

Language(s) and/or frameworks involved:
typescript, pnpm, bazel

How to reproduce

Clone
https://github.com/samuelisch/small-repo

initialize bazel on your own machine

bazel is set to 6.5.0 with `.bazelversion`

run `bazel build //rbac:tsc` for error example

run `bazel build //rbac:debug-tsc` to show that it should work fine otherwise, with genrule

Any other information?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneed: reproWe don't know how to reproduce. Please create a minimal reproducible example.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions