---
title: "loadfile"
description: "Reads and compiles a workspace Luau file without executing it."
---

```lua
loadfile(path: string): (function?, string?)
```

---

## Aliases

None.

---

## Arguments

<ParamField body="path" type="string" required>
  A UTF-8 path relative to the Byte workspace.
</ParamField>

---

## Returns

<ResponseField name="compiled" type="function?">
  The compiled chunk, or nil on compilation failure.
</ResponseField>

<ResponseField name="error" type="string?">
  A diagnostic on compilation failure; absent on success.
</ResponseField>

Compilation failure returns nil, error. File/path errors normally raise.

**Related types:** [Filesystem types & behavior](/reference/filesystem/types).

---

## Example

```lua
writefile("docs-example/module.lua", "return 42")
local fn, err = loadfile("docs-example/module.lua")
if fn then print(fn()) else warn(err) end
```
