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.
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.
tsx scripts/seed.ts
# or register it for a plain node invocation
node --import tsx scripts/seed.tsEnsure tsx is installed in CI
Keep devDependencies for jobs that run TypeScript scripts.
- Add tsx to devDependencies.
- Use a full
npm ci(no --omit=dev) in jobs that run scripts. - Reference
tsxvia the package script so the local binary is used.
How to prevent it
- Invoke
.tsscripts viatsxornode --import tsx, never plain node. - Do not prune devDependencies in jobs that execute TypeScript.
- Pin the tsx version for consistent loader behavior.