module … not found error when the all‑in‑one loader is omitted in Lua 5.4
0 reputation · 22 May 2026, 16:53 UTC
0 reputation · 22 May 2026, 16:53 UTC
Goal: understand why certain Lua 5.4 distributions exclude the all‑in‑one loader from the package.searchers chain and how this omission influences the behavior when a required module cannot be located.
Because the loader’s inclusion is implementation‑defined, the exact fallback message after all searchers fail differs between builds, and developers cannot rely on a uniform error string for automated diagnostics without first inspecting the loader table.
What factors decide whether the all‑in‑one loader is present in a given Lua 5.4 build? How does its absence change the final error message when every loader in package.searchers fails? Is there a dependable way to detect the loader’s presence at runtime that does not depend on parsing the error message?
28775 reputation · 23 May 2026, 00:15 UTC
In Lua 5.4 the package.searchers table is built by the core. The optional all‑in‑one loader is a C function that concatenates the error strings of the individual loaders and returns a single module … not found message. Whether this loader is present depends on how the interpreter was compiled:
package.searchers after the standard Lua and C loaders.--disable-all-in-one-loader (or a similar configuration option in the build system) removes it. Some embedded distributions replace it with a custom loader that mimics its behaviour but does not expose the same debug signature.When the loader is omitted, each individual loader still runs. If they all fail, Lua concatenates the error fragments it received from the Lua loader, the C loader, and any user‑added loaders. The final error string is therefore shorter and its fragments appear in the order of the remaining loaders. The generic “module … not found” text that the all‑in‑one loader supplies is missing, so the message may look like module 'foo' not found: no field package.preload['foo'] or a similar chain of fragments.
A reliable check does not rely on the final error string. Instead, inspect package.searchers for a C function whose debug source string matches the internal name used by the built‑in loader (typically luaopen_module). The following snippet demonstrates the test:
local function has_all_in_one_loader()
for _, loader in ipairs(package.searchers) do
if type(loader) == "function" then
local info = debug.getinfo(loader)
if info and info.source == "@luaopen_module" then
return true
end
end
end
return false
end
print("All‑in‑one loader present:", has_all_in_one_loader())
Key points:
debug.getinfo may return nil for C functions, and the check will report absence even though the loader exists.package.searchers against the expected default count (usually 3: Lua, C, all‑in‑one).Because the final error string is implementation‑defined, you cannot rely on it for automated diagnostics. Instead, catch the error and examine the stack field of the error object or use the detection function above to decide whether to prepend your own message.
Do you have debug.getinfo available in your build, or is the binary stripped? This determines whether the source string check will work reliably.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.