Skip to content
Latchkey

tsx "Unknown file extension .ts" in CI

The Unknown file extension ".ts" error means Node received a .ts file with no TypeScript loader active. With tsx, it indicates tsx was not invoked or registered the way the command assumes.

What this error means

A script that runs locally with tsx fails in CI with ERR_UNKNOWN_FILE_EXTENSION for .ts. The command bypassed tsx, or tsx is not installed in the CI environment.

node
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension
".ts" for /work/repo/scripts/seed.ts
  code: 'ERR_UNKNOWN_FILE_EXTENSION'

Common causes

The script ran with plain node, not tsx

A package script invoked node scripts/seed.ts instead of tsx scripts/seed.ts, so no loader handled the .ts.

tsx is not installed in CI

tsx lives in devDependencies. If CI pruned dev deps or never installed them, the tsx binary is missing and a fallback ran plain node.

How to fix it

Run the script through tsx

Invoke tsx explicitly (or register it) so Node knows how to load .ts.

Terminal
tsx scripts/seed.ts
# or register it for a plain node invocation
node --import tsx scripts/seed.ts

Ensure tsx is installed in CI

Keep devDependencies for jobs that run TypeScript scripts.

  1. Add tsx to devDependencies.
  2. Use a full npm ci (no --omit=dev) in jobs that run scripts.
  3. Reference tsx via the package script so the local binary is used.

How to prevent it

  • Invoke .ts scripts via tsx or node --import tsx, never plain node.
  • Do not prune devDependencies in jobs that execute TypeScript.
  • Pin the tsx version for consistent loader behavior.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →