Avoiding identifier collisions across obfuscated files
When several VM-obfuscated files end up in the same bundle, they can declare the same top-level identifier and crash the page at parse time. Here is why it happens and how to fix it.
The symptom
Your build runs fine, but the browser throws at parse time, before the app starts:
browser console
Error
A quick check across the bundle confirms that the same identifier is declared in more than one chunk:
terminal
Shell
Why this happens
By default, VM obfuscation uses the mangled-shuffled identifier-names generator. It walks a small alphabet in a deterministic shuffled order, and adds a vm prefix to globals introduced by the runtime. Both files emit identifiers from the same shuffled sequence — so the first global in each file shares a name, the second shares another, and so on.
Each file is obfuscated independently and the generator restarts from the beginning of its sequence for every one. When two files end up in the same bundle, the names collide. Two top-level const vmd = … declarations land in the same scope and the parser rejects the second one.
Fixes
Pick one of the following — the first option is the recommended fix:
Enable
randomIdentifiersPrefix(recommended)Each obfuscation run gets a unique random prefix prepended to every generated identifier. Names from different files no longer share a namespace, so collisions disappear without you having to coordinate prefixes by hand.
Set a unique
identifiersPrefixper fileManually pass a different prefix when obfuscating each file (e.g.
identifiersPrefix: 'auth_'for one,checkout_for another). Effective, but error-prone if you have many files — prefer the random option above.Switch
identifierNamesGeneratortohexadecimalHexadecimal names use a much larger keyspace, so the chance of two files producing the same identifier is vanishingly small. Trade-off: identifiers are longer than
mangled-shuffledoutput, so the bundle is slightly larger.Use a bundler plugin or the multi-file batch UI
Most official bundler plugins (webpack, Rollup, Vite) handle prefix uniqueness automatically across files in a build. The obfuscator.io UI also handles it when you use multi-file batch obfuscation. If you're wiring up obfuscation manually with the npm API, you have to opt in to the random prefix yourself.
Related options
randomIdentifiersPrefix— random prefix per build (recommended)identifiersPrefix— explicit prefix stringidentifierNamesGenerator— name shape (mangled,hexadecimal, …)
