samme
1
You need only 1 module script in the HTML document, e.g., main.js
. That’s the top-level module. That script can import any other modules it needs.
<script src="main.js" type="module"></script>
If you don’t mark this script as a module, you’ll see an error similar to
Uncaught SyntaxError: import declarations may only appear at top level of a module
In the browser, module specifiers are URLs (unless you use import maps). Relative URLs must start with /
or ./
or ../
.
import { Game } from "https://cdn.jsdelivr.net/npm/phaser@3.70.0/dist/phaser.esm.js";
import { gameConfig } from "./gameConfig.js";
Phaser global with modules
Phaser ESM with modules (since v3.60; experimental)
3 Likes