Quick answer: Declare the script as a module (or bundle to a classic script), keep import/export usage consistent with how each file is loaded, and use module workers where worker code imports.
import/export only work when the browser knows the file is a module — one attribute or one bundler setting. This error is the mismatch. Here is the alignment.
How to fix it
1. Add type=module
<script type="module" src="game.js"></script> — required for any file using import/export; note modules are deferred by default and scoped (no accidental globals).
2. Or bundle for classic loading
If the page must use classic scripts (portal templates, old embeds), build with a bundler outputting an IIFE/classic bundle — source keeps modules, output drops the requirement.
3. Fix workers separately
Workers importing modules need new Worker(url, { type: "module" }) — the default worker type is classic and raises exactly this error.
4. Mind CDN copy-paste
Library snippets using import must live inside module scripts; the equivalent classic build (UMD/global) exists for most libraries when you cannot switch — pick one style per page and stay consistent.
Catching the ones you can't reproduce
The hardest version of this to fix is the one you can't reproduce — it only happens on a player's hardware, OS, driver, or save state, under conditions that simply aren't present on your machine. A report that says “it crashed” or “it froze” gives you nothing to act on, so the bug survives release after release while quietly costing you players.
Automatic error capture closes that gap. Each failure arrives with its full stack trace, the device and OS, the build number, and a breadcrumb trail of what the player did right before it broke, so even a failure you have never seen becomes a specific, reproducible issue. Fold identical failures into one signature ranked by how many players each hits, and your worklist sorts itself worst-first instead of arriving as a stream of vague complaints.
This is where a tool like Bugnet earns its place. Its SDK captures every HTML5 error automatically with the full stack trace plus device, OS, memory, build, and game-state context, folds duplicates into one grouped issue with an occurrence count, and ties each to the build it first appeared on — so you fix the problem that hurts the most players first and confirm it is gone when its signature disappears from the next release.
The errors you never hear about are the ones quietly costing you players. Visibility turns them into a worklist.