# import_dynamic

> A module uses dynamic `import()`.

A module uses dynamic `import()`.

| | |
| --- | --- |
| Kind | Build or validation problem |
| Reported by | Archive and source validation |
| `disko` exit code | 1 (problems) |

A module calls `import()` to load another module at run time. Only static
`import` and `export … from` declarations are allowed, so the complete module
graph is known when the game is published.

## Why it happens

Dynamic `import()` is often used to load a level or mode on demand. In disko
every module is packaged and loaded up front, so a static import does the same
job.

## Wrong

```js title="src/main.js"
const { setup } = await import("./modes/classic.js");
```

## Right

```js title="src/main.js"
import { setup } from "./modes/classic.js";
```

To choose between modes at run time, import all of them statically and pick
one in code.

## See also

- [Project structure & imports](/games/project-structure)
- [`top_level_await`](/errors/top_level_await)
