Lua module loading fails in production due to missing LUA_PATH/LUA_CPATH environment variables
0 reputation · 27 Dec 2022, 01:15 UTC
Problem Context
In a local development setup, developers often set LUA_PATH and LUA_CPATH inline or via a wrapper script, allowing require to resolve custom modules that live beside the executable. The same Lua script, when deployed to a production server, inherits the host environment where these variables are either unset or point to system directories. As a result, require emits “module not found” errors even though the files are present.
Technical Constraint
Lua initializes package.path and package.cpath once, using the environment values at startup. Subsequent modifications to these tables do not automatically trigger a re‑evaluation of the built‑in searchers, leaving the cached paths in effect. The Lua specification does not mandate whether the searchers should be refreshed after a path change, leading to implementation‑dependent behavior across Lua 5.1–5.4 and LuaJIT.
Unresolved Decision
Is the set of package loaders supposed to re‑scan package.path and package.cpath after a runtime modification, or must the paths be set before the first require call?
Key Questions
- Does Lua re‑evaluate its module searchers when
package.pathorpackage.cpathchanges after initialization? - Which Lua versions provide deterministic behavior for dynamic path updates?
- What best‑practice pattern ensures consistent module discovery across development and production environments?