"Circular requiring" infinitely yields thread and no warning or error is shown

This is definately not expected behaviour!

I just did a quite long time debugging to figure out that I was “circularily” requiring a script. A basic repro is simple to make:

  1. Insert 2 modulescripts and 1 script in Workspace.
  2. Name the ModuleScripts “a” and “b”

game.Workspace.a:
require(game.Workspace.b)
return {} – this is to prevent the “return error”

game.Workspace.b
require(game.Workspace.a)
return {}

game.Workspace.Script:
require(game.Workspace.a)
print(1)

Notice that print(1) is never used: 1 does not get printed.

What I think is happens is that there is an internal error being triggered. If not, then this would either run an infinite loop, or if it would just return “previous loaded modules” it should actually return something… which clearly doesnt happen. What I do know is that it “yields” (probably internal errors) when requiring an already required module script (from inside a module) for the second time.

I checked what happens in normal Lua. For a quick repro, use this bash script:

mkdir module_loop
cd module_loop
touch a.lua
touch b.lua
echo "require('b')" >> a.lua
echo "require('a')" >> b.lua
touch c.lua
echo "require('a')" >> c.lua
lua c.lua

This shows the following error:

In “normal” Lua, “circular requiring” (I guess the right “lua term” is “requiring in a loop”) the code clearly errors.

If it would atleast show a warning, that would be nice! :slight_smile:

1 Like

off topic, you dont have to return a table. As long as the value you return isnt nil/false, its good

I just return true instead of a table

You can even return functions and call them require(FunctionModule)()

[quote] off topic, you dont have to return a table. As long as the value you return isnt nil/false, its good

I just return true instead of a table

You can even return functions and call them require(FunctionModule)() [/quote]

I know! :slight_smile: It’s just my default action to return an emtpy table.

[quote] off topic, you dont have to return a table. As long as the value you return isnt nil/false, its good

I just return true instead of a table

You can even return functions and call them require(FunctionModule)() [/quote]

I know! :slight_smile: It’s just my default action to return an emtpy table.[/quote]

Lua 5.1 module syndrome :stuck_out_tongue:
I do the same.