Internal compiler error (JSC_ILLEGAL_MODULE_RENAMING_CONFLICT) on duplicate var declarations in ES module mode

Author: sbc100Created Sep 18, 2026Updated Sep 18, 2026

I found this issue running closure on emscripten-generated code (which uses a lot of var still).

When compiling ES modules (using --chunk_output_type ES_MODULES or on inputs containing ES module syntax such as import.meta), having duplicate top-level var declarations causes Closure Compiler to crash with a fatal Internal Compiler Error:

ERROR - [JSC_ILLEGAL_MODULE_RENAMING_CONFLICT] Internal compiler error: rewritten module global name <name>$$module$<file> is already in use.

Per the ECMAScript specification, top-level var declarations in modules are hoisted to module scope and may be repeated (unlike lexical let / const declarations).

Repro:

javascript
import.meta.url;                                                                     
var a = 1;                                                                           
var a = 2;                                                                           

(Alternatively, using repeated loops:

javascript
import.meta.url;                                                                     
for (var i = 0; i < 10; ++i) {}                                                      
for (var i = 0; i < 10; ++i) {}                                                      

)

bash
$ google-closure-compiler --compilation_level ADVANCED_OPTIMIZATIONS --language_in UNSTABLE --chunk_output_type ES_MODULES repro.mjs
repro.mjs:1:0: ERROR - [JSC_ILLEGAL_MODULE_RENAMING_CONFLICT] Internal compiler error: rewritten module global name a$$module$repro is already in use.
Original definition: {1}                                                             
  1|-                                                                                
     ^                                                                               
  2| import.meta.url;                                                                
     ^^^^^^^^^^^^^^^^                                                                
  3| var a = 1;                                                                      
     ^^^^^^^^^^                                                                      
  4| var a = 2;                                                                      
     ^^^^^^^^^^                                                                      
                                                                                     
1 error(s), 1 warning(s)