Hi there.
I am creating a permissions system and am trying to import a table of permissions from a module script. In order for this to work, I have set up permissions_config: ModuleScript as an argument for the function below.
This is then imported using require(), however it seems this is an invalid use of the argument.
According to require() documentation, this is correct usage.
The error message I receive is “Unknown require: unsupported path”.
I would appreciate it if someone could explain why this is wrong and how I can work around this limitation.
Thanks!
-- returns whether a player has sufficient clearance to access.
function permissions.player_has_clearance(player: Player, permissions_config: ModuleScript): boolean
local permissions_table = require(permissions_config)
local team_name = if player.Team == nil then nil else player.Team.Name
local department: TYPES.Department = team_name_into_department(team_name)
return
player_has_clearance(player, permissions_table[department])
and player_in_department(player, department)
end
*I am aware I could use value objects to work around this, but I find this solution more elegant as it provides strong type checking and improved robustness.
You are getting this because Luau’s linter can’t resolve the path of the module.
According to the Typechecking section of the Luau website, when attempting to require a module script it must be done statically. To quote:
Let’s say that we have two modules, Foo and Bar. Luau will try to resolve the paths if it can find any require in any scripts. In this case, when you say script.Parent.Bar, Luau will resolve it as: relative to this script, go to my parent and get that script named Bar.
There are some caveats here though. For instance, the require path must be resolvable statically, otherwise Luau cannot accurately type check it.
Thanks for the help,
In other words, the path cannot be passed in as an argument and I will have to use some value objects to get around this limitation?