TS6421
TypeScriptERRORNotableConfigHIGH confidence

Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import ...

Production Risk

Build will fail; resolve before shipping.

What this means

A compiler configuration error (TS6421): Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files.. This diagnostic is emitted by the TypeScript compiler when rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files..

Why it happens
  1. 1Incorrect TypeScript syntax or type usage
  2. 2Type mismatch between declared and actual value
How to reproduce

TypeScript compiler reports TS6421 during type checking.

trigger — this will error
trigger — this will error
// Triggers TS6421
// Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files.

expected output

error TS6421: Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files.

Fix

Fix the tsconfig.json option

WHEN When a compiler option is invalid or missing

Fix the tsconfig.json option
// tsconfig.json
{
  "compilerOptions": {
    // Review and correct the flagged option
  }
}
// Run: npx tsc --showConfig to see effective config

Why this works

TypeScript validates tsconfig.json options; check the official tsconfig reference for valid values.

Sources
Official documentation ↗

TypeScript Compiler Diagnostics

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All TypeScript errors