Running async code in the main body of a required module throws an error
Closed this issue · 0 comments
filiptibell commented
module.luau
net.request("https://google.com")
return {}
script.luau
require("./module")
There are at least two ways to solve this:
- Make
require
async and use async filesystem APIs, but this is really tricky with caching and making sure requires only happen once (users can runrequire
in atask.spawn
, ..) - Use a bundler to always bundle scripts that run, even in the CLI, to not have to use require at all, this would disallow dynamic requires, and potentially mess up stack traces
Note that this bug does not occur unless it is in the main script of the required module, this works fine:
module2.luau
return function()
net.request("https://google.com")
end
script2.luau
require("./module2")()