Hello, everyone!
We are excited to announce a new Luau feature available in the Roblox engine: require by string! With this feature, you’ll be able to use string paths to require modules instead of navigating with Instances, making your code compatible with Luau code written for other runtimes and easier to read and write.
Details
String Path Resolution
Require-by-string allows you to require modules using relative paths.
- The
/
symbol is used as a separator in paths. - Relative paths must start with
./
or../
.
For example, these two require
calls are now equivalent.
local Module = require(script.Parent.Parent.Folder.ModuleScript)
local SameModule = require("../Folder/ModuleScript")
Init Support
Important: Some external tools such as Rojo have different semantics for files called
init.luau
. See our external tools section in the FAQ for more information.
Additionally, you can now require Instances containing a ModuleScript
named Init
or init
. This aligns with the behavior we support for folders in external Luau code, where the folder’s init.luau
script is used as the entry point. With this change, you can organize your code into a folder and require the folder itself, simplifying your project structure!
Autocomplete
To aid with development, autocomplete suggestions will pop up in Script Editor for each component as you type out paths in a require
expression.
Type Checking
With strict mode enabled, you’ll also receive a type error for any path that cannot be resolved to a ModuleScript
.
Conclusion
This new feature, along with the early preview for Studio Script Sync, will make it easier for you to work with Luau written outside of Roblox. We’re excited for you to try out require-by-string, and we welcome your feedback. Please share your thoughts and experiences in this thread!
FAQs
Does require-by-string wait for ModuleScripts to replicate?
No, but waiting for game.Loaded
to be fired using game.Loaded:Wait()
will be sufficient when your scripts are not in Workspace. Otherwise, you can use Instance:WaitForChild()
for manual synchronization.
Are absolute paths supported?
No. We intend to remain aligned with open-source Luau, which does not support requiring absolute paths. However, we are already working on solutions to make it easier to access common libraries regardless of where your scripts are in the experience or on the file system.
Are aliased paths supported?
Not yet, but we’re working on it! Support for aliases in require paths is an important step toward full cross-platform compatibility.
How does this work with external tools?
We decided to keep the current behavior for init
files to ensure consistency with how Luau works outside of Roblox. While this decision may not fully address every use case, it helps avoid breaking existing projects and is the first step towards a unified Luau ecosystem.
For most external tools, you’ll be able to use require-by-string without issue. However, some tools have different semantics for init
files, which may lead to compatibility issues.
In particular, Rojo treats init
files as if they are the same as the directory they are in, converting them to ModuleScript
Instances with children when importing them into Roblox. Visit Rojo: Sync Details to learn more. You’ll still be able to use require-by-string with Rojo, but you should be aware of this potential issue when importing projects.
To address this, we’re planning to introduce project-relative requires which will provide a consistent way to reference files in Roblox, on the file system, and when using external tools such as Rojo. We’ll share more details about that in the future. However, for now this is just the first step to enabling consistency between Luau runtimes.
Documentation
For additional information about require
, please visit our documentation .