Diagnostic reference
SyntaxError: Identifier 'X' has already been declared
Fix SyntaxError: Identifier 'X' has already been declared in Google Apps Script when two .gs files declare the same top-level const, let, or class name.
Updated December 6, 2026
Apps Script error
SyntaxError: Identifier 'SHEET_NAME' has already been declared
What it means
Every .gs file in an Apps Script project executes in one shared global scope rather than isolated ES modules. Declaring the same top-level const, let, or class name in two different .gs files (or twice in the same block) throws Identifier has already been declared as soon as any function runs.
Related error messages
- SyntaxError: Identifier 'ss' has already been declared
- SyntaxError: Identifier 'CONFIG' has already been declared
Before and after
The code before and after the fix.
// File 1: Code.gs
const SHEET_NAME = 'Orders';
// File 2: Helpers.gs (shares the exact same global scope in Apps Script)
const SHEET_NAME = 'Archive';// File 1: Code.gs
const ORDERS_SHEET_NAME = 'Orders';
// File 2: Helpers.gs
const ARCHIVE_SHEET_NAME = 'Archive';How to fix it
- Search across every .gs file in the project for the identifier name and rename or consolidate duplicate top-level const, let, or class declarations.
- Move variables that belong to one operation inside the function that uses them instead of declaring them at the top level.
- Group shared project settings under one namespace object (for example const CONFIG = { ... }) in a single Config.gs file.
Things to check
- Top-level function declarations with the same name do not throw a SyntaxError; instead, the later file silently overwrites the earlier function. myFunction flags duplicate functions under rule MF92003 and duplicate const/let declarations through type checking.
- Apps Script .gs files do not support ES module import or export statements.
In the Apps Script editor
Catch errors like this before clicking Run.
myFunction (published as Error Checker for Google Apps Script on the Chrome Web Store) checks your code while you edit at script.google.com. Diagnostics, autocomplete, and rule-based quick fixes are free without an account, run in your browser, and request no Google Drive, Gmail, or Apps Script project OAuth scopes. Writing Apps Script with an AI coding agent? Connect the Apps Script MCP server to run the same static checks before pasting code.