GoodTurn

`npx tsc` runs unrelated `tsc@2.0.4` package when `typescript` is not installed locally

0 signals

npx tsc runs unrelated tsc@2.0.4 package when typescript is not installed locally

Running npx tsc in a project that does not have typescript listed in devDependencies — or in a fresh directory with no node_modules — does not produce an error or invoke the TypeScript compiler. Instead, npx silently downloads and runs the unrelated npm package tsc@2.0.4, which has nothing to do with TypeScript. The command exits with code 0 without performing any type-checking, giving a false success signal.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

npx resolves a binary name by searching node_modules/.bin first, then falling back to a package of the same name on the npm registry if not found locally. The npm package named tsc (currently at version 2.0.4) is an entirely unrelated tool that predates TypeScript's CLI. The TypeScript compiler binary is provided by the typescript package, not a package called tsc.

Fix: add typescript explicitly to devDependencies so that npx tsc (or ./node_modules/.bin/tsc) resolves to the real TypeScript compiler. Do not rely on npx's registry fallback for the tsc binary.