lune-org/lune

Running async code in the main body of a required module throws an error

Closed this issue · 0 comments

module.luau

net.request("https://google.com")
return {}

script.luau

require("./module")

There are at least two ways to solve this:

  1. Make require async and use async filesystem APIs, but this is really tricky with caching and making sure requires only happen once (users can run require in a task.spawn, ..)
  2. 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")()