Skip to content

rtk pnpm typecheck incorrectly rewrites command to pnpm tsc #2809

Open

Description

@tanakalucky

Description

When running rtk pnpm typecheck in the root of a project, rtk incorrectly rewrites the command to pnpm tsc (or runs tsc directly), executing a TypeScript build rather than running the typecheck script defined in package.json.

In the reproduction project's package.json, typecheck is defined to use Turborepo:

"scripts": {
  "typecheck": "turbo run typecheck"
}

Instead of running pnpm run typecheck (which would trigger turbo run typecheck), rtk rewrites and executes pnpm tsc.

Reproduction Repository

A minimal reproduction repository is available here:
https://github.com/tanakalucky/rtk-pnpm-typecheck-rewrite-test

Steps to Reproduce

  1. Clone the reproduction repository and navigate into it:
    git clone https://github.com/tanakalucky/rtk-pnpm-typecheck-rewrite-test.git
    cd rtk-pnpm-typecheck-rewrite-test
  2. Install dependencies:
    pnpm install
  3. Run the reproduction command:
    rtk pnpm typecheck

Expected Behavior

rtk should execute pnpm typecheck, which in turn runs the script defined in package.json (turbo run typecheck).

Actual Behavior

rtk rewrites the command to pnpm tsc (or runs tsc directly) and starts a compiler build, ignoring the custom script definition in package.json.

Activity

  1. pszymkowiak commented on Jul 4, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 88%

    Summary

    rtk's command-rewrite logic incorrectly maps pnpm typecheck to pnpm tsc/tsc instead of passing through to the package.json script (e.g. turbo run typecheck); fix the pnpm rewrite rule to respect custom script definitions.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/rewrite/pnpm.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  2. EDM115 commented on Jul 30, 2026

    @EDM115

    actually, rtk should use its tsc filter only if the typecheck script contains it.
    matching for that however can be complex :

    • matching simply for the command starting with tsc won't cut it since we can have env vars set
    • matching for tsc in the middle of the command can also be wrong, what if our typecheck command actually runs tsc --noEmit; cd src/rust && cargo check --all-targets --all-features ? command separators are also different based on platforms
    • matching for tsc alone might also be wrong, what if we call vue-tsc ? or run a tsc.sh file that does some stuff before calling itself pnpm exec tsc ?
  3. KuSh commented on Sep 12, 2026

    @KuSh
    Collaborator

    Adding evidence found while reviewing #3676, which would have made this fire by default for every user rather than only for people who explicitly type rtk pnpm typecheck.

    There is a write side effect that isn't in the original report: the dropped --noEmit causes tsc to emit compiled JavaScript into the project.

    main.rs:2096 dispatches PnpmCommands::Typecheck to tsc_cmd::run(Some("pnpm"), &args, …), which runs tsc with only the args after typecheck. For a bare pnpm typecheck that list is empty, so every flag the script carried — including --noEmit — is lost.

    Reproduced on current develop (79b96a4), real project, "typecheck": "tsc --noEmit", tsconfig.json with outDir: "./dist":

    # pnpm 12.4.1
    $ pnpm typecheck
    $ tsc --noEmit
    exit=0        dist/ -> does not exist
    
    $ rtk -v pnpm typecheck
    Running: pnpm tsc
    TypeScript: No errors found
    exit=0        dist/ -> index.js        <-- written
    
    # pnpm 9 (same result, reached via bare `tsc` since tool_exists("tsc") is false there)
    $ rtk -v pnpm typecheck
    Running: tsc
    exit=0        dist/ -> index.js        <-- written
    

    A read-only type check acquires a write side effect. On a project whose typecheck script is not tsc at all, the same path turned exit 0 with 1392 bytes of real output into exit 1 with a fabricated TypeScript: No errors found.

    Other shapes broken by the same mechanism, beyond the Turborepo case in the report:

    • "typecheck": "vue-tsc --noEmit" / svelte-check — the wrong binary runs; for .vue / .svelte the result is meaningless
    • "typecheck": "tsc -b" — project-references build, not a plain check
    • "typecheck": "tsc -p tsconfig.app.json" — the default tsconfig.json is checked instead, so a green result is a false pass over a different file set
    • monorepo root with no tsconfig.json — bare tsc errors where pnpm typecheck would have fanned out to workspaces
    • tsc not on PATH — tool_exec(…, MissingTool::Fetch) pulls TypeScript from the network

    Two possible fixes, depending on what rtk pnpm typecheck is meant to be:

    1. Make PnpmCommands::Typecheck actually run pnpm typecheck and filter the tsc-shaped output it produces, keeping the script as the source of truth; or
    2. Drop the Typecheck variant entirely and let it fall through to PnpmCommands::Other → passthrough, the way test / build / format already do.

    Option 2 is the smaller change and matches what the other script names already do. Option 1 keeps the filtering benefit but has to stop assuming the script is tsc.

    Either way the validate_pnpm_filters FIXME in main.rs is standing evidence that this delegation was already known to be lossy.

  4. Jayllyz commented on Nov 27, 2026

    @Jayllyz

    Another repro, on a project where the typecheck script does not use tsc at all and tsc is not installed.

    Environment

    • rtk 1.2.1
    • pnpm 12.23.0
    • Linux x86_64

    package.json

    "typecheck": "tsrs --noEmit --fast"

    Expected (rtk proxy pnpm typecheck)

    $ tsrs --noEmit --fast
    src/components/example.tsx(77,30): error TS2339: Property 'foo' does not exist on type '...'.
    src/components/example.tsx(77,93): error TS2339: Property 'bar' does not exist on type '...'.
    [ELIFECYCLE] Command failed with exit code 2.
    

    Actual (rtk pnpm typecheck)

    TypeScript: compiler exited with code 1, but RTK parsed no diagnostics
    Error: ERR_PNPM_RECURSIVE_EXEC_FIRST_FAIL
      × Command "tsc" not found
    

    Impact

    • The package script never runs. rtk runs pnpm exec tsc instead.
    • The two real type errors are hidden. The output shows only an unrelated "tsc not found" error.
    • The exit code changes from 2 to 1.
    • This happens only with the explicit rtk pnpm typecheck form. The hook does not rewrite a bare pnpm typecheck (rtk rewrite "pnpm typecheck" exits 1).

    Workarounds: rtk pnpm run typecheck (runs the real script, exit code 2 kept) or rtk proxy pnpm typecheck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions