Log inGet started

Requiring modules

Updated December 3, 2026
  • by identity — a name in the asset index, which the engine resolves to an asset and then to that asset's code file;
  • by path — a literal location in the VFS hierarchy, walked like a directory tree.

You never choose between them with a flag. The engine reads the shape of the string and decides. Get the shape right and resolution is unambiguous; get it wrong and you get a loud "not found" rather than a surprise. This guide is about reading that shape.

The mechanism: shape → identity-or-path → asset → primary file

Every require runs the same pipeline:

  1. Classify by shape. Does the string carry a type suffix (.module, .tool, …) and/or a /? Then it's a path. Is it a suffix-free token, plain or dotted (json, modules.transform)? Then it's an identity. A leading . / .. / ./ / ../ marks it relative — anchored to the file doing the requiring — and the same suffix test then says whether that relative form is an identity (.helper) or a path (./helper.module).
  2. Resolve to an asset. An identity is looked up in the asset index — the string is a registry key, never parsed into a folder. A path is walked literally in the VFS from wherever it's anchored. Either way you land on one asset.
  3. Resolve the asset's primary file. Every asset type names a primary code file — a .module's primary is its init.luau, and so on. require loads that file. This is why you can require a module by its folder and never name init.luau yourself.

The throughline: identity and path are two front doors to the same back room. Both converge on an asset, then on that asset's primary file. The shape only decides which front door you walk through.

The module runs once, and every later require of it hands back that same loaded instance. So a table a module returns is shared state: a field on it that a component sets is the field an execute call reads. That is what makes a module's returned table the way one chunk observes another's state — the scripting-and-tasks guide covers the state model.

Saving a module's source re-runs its body and folds what it returns into that same instance, so every reference held to it stays live. The tables it exports keep their identity the same way: where the previous source and the new one both build a table at a key, that table stays and the new source's keys land on it. So a handler another chunk registered into an exported bus is still registered after the save, and an edit to a constant table the module exports is what that table reads. A key the previous source declared and the new one drops goes away; a key something set at runtime stays. The body's own locals start again from their initial values, because the body runs again; state that has to outlive an edit lives in modules.state(), the same table on both sides of every reload.

A few built-in modules carry the person's private data or an agent's calls: the agent memory store (@builtin::modules.memory), the tool dispatch (@builtin::modules.tools, the tool wrapper @builtin::assetTypes.tool.behavior), the Memory panel (@builtin::editor.edui.memoryPanel) and the registry of the editor's agent prompt targets (@builtin::editor.edui.agentPrompt). Each declares --!realm engine in its header, and the engine's own code runs on an instance of it that is the engine's alone: every module that instance requires is loaded for it too, so it calls through no table, function or environment that other code holds. Code a world ships that requires one of them gets an instance of its own, the same one each time, shared by the world's code: its fields, registrations and replacements are its own, and none of them reaches the engine's instance. getfenv and setfenv refuse such code an environment of the engine's instances.

-- in a world module
local memory = require("@builtin::modules.memory")
memory.write = function(...) end            -- replaces the world's own copy; the agent's memory tools never call it

Hold onto one fact before the forms: an identity is never a path. @builtin::modules.transform does not "mean" the folder /zero/source/libs/@builtin/modules/transform — it means the index entry named modules.transform in the @builtin root. Where that asset's bytes physically live is incidental; the index knows, and you don't have to.

The forms

Cross-root identity — @<scope>::name

@scope:: is a root rekey. It says "resolve the rest of this string in library scope's root, not in mine." The library's own location is found through the index.

After the ::, a suffix-free remainder is an identity within that root:

local Transform = require("@builtin::modules.transform")   -- → table

The dotted token modules.transform is the index key inside @builtin. This is the everyday way to reach a built-in module from your own world: rekey to @builtin, then name the identity.

Cross-root path — @<scope>::a/b.module

Give the remainder a / and full type suffixes and it flips from identity to path — a literal location walked inside that library's root:

local Pathfinding = require("@builtin::systems/pathfinding.package/pathfinding.module")   -- → table

This addresses the file tree directly: systems/pathfinding.package/pathfinding.module is a real folder under @builtin, and naming the .module directory resolves to its primary file. Reach for this when you want a specific file by where it sits rather than by its indexed name.

Bare token — current-root identity

A suffix-free token with no @scope:: is an identity in the requiring file's own root:

-- inside a module that itself lives in the @builtin root:
local Transform = require("modules.transform")   -- → @builtin::modules.transform

This is the same identity lookup as @scope::, with the root left implicit as your root. The consequence catches people out: a module in your world source that writes require("modules.transform") looks for modules.transform in the world root, finds nothing, and fails —

-- inside a module under /zero/source (the world root):
require("modules.transform")
-- → error: module 'modules.transform' not found

— because the built-in lives in @builtin, not your world. The bare token is not shorthand for the VFS path /zero/source/modules/transform; it is an index lookup in your root. To cross into the engine's library, rekey: require("@builtin::modules.transform").

The token is the whole identity, so it names the asset whose identity is exactly that. From world code, require("lonely") reaches /zero/source/lonely.module, and a module at /zero/source/nest/lonely.module answers to require("nest.lonely").

A world-root name that starts with a package's name and that no world asset holds is that member of the package, wherever the package sits. In the world that authored game.package, require("game.util") and the same name rekeyed with @root:: reach game.package/util.module by its path; installed into another world, the package lands under /zero/source/deps/<owner world>/, and the same requires, written in the package's own code or in the installing world's, reach the same module there (the one require("~game.util") loads). A name two installed packages share reaches neither of them, and the error names the identity that reaches each copy.

Relative — anchored to the requiring file

Two relative spellings, both anchored to the file doing the require, and the suffix test tells them apart.

Dot form — relative identity. Suffix-free, walks the module hierarchy (siblings and ancestors by logical name):

-- inside helper's sibling module:
local helper = require(".helper")        -- the sibling identity → table

A module that owns modules of its own (a .module folder holding more than its init.luau) reads .name as its own child when one answers to that name, and as its sibling otherwise.

Slash form — relative path. Full names with type suffixes, walks the directory tree:

local helper = require("./helper.module")     -- sibling folder → its primary
local up     = require("../target.module")    -- climb one directory, then resolve

./ is the directory the requiring module sits in, and ../ climbs one level from there. A module's init.luau speaks for its folder, so from game.package/view.module/init.luau, ./helper.module is game.package/helper.module (the same module .helper names) and ../target.module sits beside game.package. Any other file anchors in its own directory: from gb.module/cpu.luau, ./cpu_cb.luau is gb.module/cpu_cb.luau. A .module directory resolves to its primary file; naming a specific file (../shared.tool/extra.luau) loads that file as-is, which is how you reach a submodule inside a composite asset.

Every relative form means one place everywhere it is read: the running engine, the diagnostics the editor shows, and the dependency table a push records and an install in another world pulls from.

Root-relative: ~.name, and ~package.name

~ stands for the nearest root enclosing the requiring file, so ~.name is an identity rooted at that root's folder, whatever folder the requiring file is in. A root is a package, or any asset whose type declares root: true in its type.yaml: a type that is its own implementation keeps that implementation inside itself and reaches it from its own root. assetType, plugin and effect are roots, and a type you define is one when its type.yaml says so.

-- inside game.package/view.module/init.luau:
local util = require("~.util")            -- game.package/util.module
local deep = require("~.helpers.deep")    -- game.package/helpers/deep.module
-- inside track.assetType/behavior.luau:
local mesh = require("~.mesh")            -- track.assetType/mesh.module

The engine walks up from the requiring file to its nearest enclosing root and resolves the rest of the string as an identity under it, each further . stepping one folder down; where roots nest, the innermost wins. asset.resolve reads the same form, so a root's code reaches its own shaders, materials and modules without naming the root: asset.resolve("~.shaders.vignette", "shader"). The folder is what ~ names, so each copy of a root reaches its own members: each copy's ~.util is the util in that copy's folder. From a file inside no root, ~.name is a "not found" that says so.

What a package adds over any other root is its name. ~ followed by a name, with no dot between, names a package by that name within its scope: require("~game.util") reaches util in the world's package whose package.yaml says name: game, and a package inside a library goes by @<lib>::~<name> (require("@physics::~rigid.body")). The name is the one package.yaml states, which can differ from the folder's name. Both spellings reach the same loaded module as its full identity does.

Why ./helper is rejected

The suffix is the form-marker, and it is mandatory on the slash form:

require("./helper.module")   -- ✓ a path — resolves the sibling folder
require(".helper")           -- ✓ an identity — resolves the sibling by name
require("./helper")          -- ✗ error: module './helper' not found

./helper is a path (the ./ says so) that is missing its type suffix, so it names no real VFS entry; and it isn't a dotted identity either (the ./ disqualifies it). It is neither valid form, so it fails loudly rather than guessing. Write ./helper.module (path) or .helper (identity) — pick the door, name it fully.

One asset → one primary file

Whatever the form, resolution ends at an asset, and the asset type picks the code file to load. That is what makes "require the folder" work, and it is also why require is for code: requiring a scene such as @builtin::scenes.test_arena raises module '…' not found, naming the scene.

A .scene's primary file is its scene data (JSON), not Luau. require converges on the scene asset, finds its primary isn't code, and stops with a clean "not found." It does not hand the JSON to the Luau compiler. Requiring a .material, or any data asset, fails the same clean way — require is the door for modules, and data assets are loaded through their own APIs.

Unresolved is loud, never silent

Every failure above is the same failure: a clear "module not found." This is deliberate and load-bearing.

require("no_such_bare_token")         -- → error: module 'no_such_bare_token' not found

A rekeyed identity that no entry in that root holds fails the same way, and the error names the whole identity you wrote, @builtin:: and all.

An identity with no index entry, or a path with no VFS entry, fails immediately. What it will never do is fall through — take an identity string, bend it into a folder path, and compile whatever file happens to sit there. A miss is a miss, reported as one, at the point you asked. When a require fails, read the form against the rules above: wrong root (use @scope::), wrong door (suffix on a slash path), or the asset genuinely isn't there.

The model to carry

Read the shape, and the rest follows: suffix or / ⇒ path (walked literally in the VFS), suffix-free token ⇒ identity (looked up in the index), leading dot ⇒ relative to the requiring file (and the suffix again says identity vs path), leading ~. ⇒ root-relative identity. Both roads end at one asset and its primary code file. @scope:: rekeys which root an identity resolves in; a bare token uses your own root. And a require that can't find its target says so, plainly, instead of resolving something you didn't ask for.

  • documentation
  • guide