Error guides

Fix "Identifier 'X' has already been declared" in Apps Script V8

SyntaxError: Identifier 'TAX_RATE' has already been declared

Why it happens

Every .gs file in a project is loaded into one global scope, in the order shown in the editor. With var and function, a second declaration just overwrites the first. With const, let and class, declaring the same name twice — even in different files — is a SyntaxError in V8.

Rhino-era projects often copy the same const CONFIG = … into several files.

The fix

Keep a single declaration in one file (e.g. Config.gs) and delete the copies:

// Config.gs
const TAX_RATE = 0.07;
const REPORT_SHEET = 'Report';

// Code.gs and Feed.gs: just use TAX_RATE

If the copies hold different values, rename them (FEED_TAX_RATE) — in Rhino the last file loaded silently won.

Related: file order

Top-level code that reads a const/let/class from a file listed later in the editor throws ReferenceError: Cannot access 'X' before initialization. Move shared declarations to the first file, or read them inside functions.

How V8Shift handles it

V8Shift indexes top-level declarations across every uploaded file, flags each duplicate with the other file names, and switches duplicate const/let to var (marked for review). Duplicate class declarations stay manual.

Have a whole project to migrate? Paste your .gs or upload a zip for a free V8 compatibility report — every occurrence of this pattern with file and line, plus an auto-rewritten project.
Related errors