Skip to content
Latchkey

TS2451: Cannot redeclare block-scoped variable - in CI

A let/const name was declared twice in the same scope, or a file without imports/exports collides with global declarations.

What this error means

Type-checking fails with TS2451 naming the redeclared variable, sometimes across two files treated as one global scope.

tsc
src/index.ts(1,7): error TS2451: Cannot redeclare block-scoped variable 'name'.

Common causes

How to fix it

Make the file a module

  1. Add an import or export so the file gets its own module scope
ts
export {}

Rename or remove the duplicate

  1. Rename one declaration, or delete the redundant one

How to prevent it

  • Use modules (import/export) rather than global scripts, and avoid names that shadow DOM globals.

Related guides

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