v0.13.7
errors and warnings / parsing

errors and warnings / parsing / E0108

E0108 error

import / export not at the top level of a module

area
parsing (x01xx)
fails the build
yes

import or export is inside a block (a function, if, loop or do). Both only work at the top level of a file: imports are resolved when the file loads, and exports become the module's table. Move the import to the top of the file, and export a top-level declaration.

Example

× failswowlua
local function start()    import after from "wowlua:timer"    after(1, function() print("started") end)endstart()
✓ compileswowlua
import after from "wowlua:timer" local function start()    after(1, function() print("started") end)endstart()

The compiler reports it like this:

error[E0108]: `import` is only allowed at the top level of a file
  ┌─ src/main.wowlua:2:5
  │
2 │     import after from "wowlua:timer"
  │     ^^^^^^ here
codemessage
E1011Top-level import after another (non-import) statement
E0115class, enum, declare or overload function not at the top level of a file

Offline

terminal
$ wowlua explain E0108
E0108 (error): import / export not at the top level of a module

source on GitHub ↗