Docs menu

E021: export mut isn't a thing yet -- only export immut is

What compiler error E021 means, and how to fix it.

Turf lets you share a constant value across multiple files with export immut, but it doesn’t yet support sharing a value that other files could change – a true mutable global. So writing export mut trips this error, even though a plain, non-exported mut variable is completely normal everywhere else in Turf.

Example
export mut counter: int = 0;

This looks reasonable, but counter being both mut (changeable) and shared across files at the same time isn’t supported. If you just need a constant that many files can read, swap mut for immut:

Example
export immut MAX_USERS: int = 100;

Now every file that imports this one can read MAX_USERS, and since it’s immut, there’s no ambiguity about who’s allowed to change it (nobody – that’s the point).

If you genuinely need a value that changes and is visible everywhere, that’s not something export can do for you right now. The usual workaround is to keep the mutable value local to one file and let other files interact with it through a function you write yourself – something like a get_counter()/set_counter() pair – rather than reaching in and changing it directly. It’s a bit more typing, but it also means you always know exactly which piece of code is allowed to change the value, which tends to save you from confusing bugs down the road anyway.

Run turf --explain E021 in a terminal to read this again.

Last updated: Oct 15, 2026Edit this page on GitHub

Esc

Type to search.