Short answer
Find the two declarations of the name in the message. If they are in the same block, rename one or drop the second let or const and assign to the first. If one is an import, rename the local variable or import with as. In a switch, wrap each case in braces. In the browser, if the file is fine, the same script is probably loaded twice, or two classic scripts declare the same top-level name.
Why the name is taken, and the fix
01
Two declarations in the same scope
“let declarations cannot be in the same scope as any other declaration, including let, const, class, function, var, and import declaration.” MDN, let: Redeclarations
Often from pasting code, or an AI edit that added a block without removing the old one. Keep one declaration and assign to it.
// wrong let total = 0; let total = items.length; // right let total = 0; total = items.length;02
A local name that clashes with an import or a parameter
“A let declaration within a function's body cannot have the same name as a parameter.” MDN, let: Redeclarations
import { user } from './store' and then const user = ... in the same module, or a function parameter redeclared with let. Rename the local value, or import under another name.
import { user as storeUser } from './store'; const user = storeUser ?? guest;03
The same name in two switch cases
“To avoid the error, wrap each case in a new block statement.” MDN, let: Redeclarations
All cases of a switch share one block, so let message in two cases is a redeclaration.
switch (status) { case 'ok': { const message = 'Saved'; break; } case 'error': { const message = 'Try again'; break; } }04
A script loaded twice, or two scripts using one name
“if you declare a let or const variable in the first script, declaring it again in the second script will cause a redeclaration error.” MDN, let: Temporal dead zone
Classic script tags share one top-level scope. If a page includes the same file twice, or two files both declare const API_URL at the top level, the second one throws. Load the file once, or make the scripts modules (type="module"), which each get their own scope. Modules also stop top-level names becoming globals, so check that nothing reads them from window.
<script type="module" src="/js/app.js"></script>
Checked against the vendor’s docs on : MDN: let.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: JavaScript “x is not defined” · “Unexpected identifier” · “Invalid or unexpected token”