Strange "require" bug

I have this line of code:

local game_data = require( "modules.save_data.shared_data").game

I have the same line in few files and it works fine. But in one concrete file this line broke bundle (all platforms) and editor’s 1 build (editor2 build works fine). I recieve next error:

ERROR:SCRIPT: modules/onet/view/view.lua:7: module 'modules.save_data.shared_data' not found:
no file 'modules.save_data.shared_data'
stack traceback:
[C]: in function 'require'
modules/onet/view/view.lua:7: in main chunk
[C]: in function 'require'
collections/scenes/game/ui/left_bar.gui_script:3: in main chunk
ERROR:SCRIPT: collections/scenes/game/ui/left_bar.gui_script:3: loop or previous error loading module 'modules.onet.view.view'
stack traceback:
[C]: in function 'require'
collections/scenes/game/ui/left_bar.gui_script:3: in main chunk
WARNING:RESOURCE: Unable to create resource: /Users/agulev/Downloads/test/x86_64-darwin/Onet Collectible.app/Contents/Resources/game.dmanifest/collections/scenes/game/ui/left_bar.gui_scriptc
ERROR:SCRIPT: collections/scenes/game/entry_point.script:4: loop or previous error loading module 'modules.onet.view.view'

If I change this line to

local game_data = require "modules.save_data.shared_data".game

bundles and build works fine.

What can it be?

We have a really stupid regex that parses script files in search for require directives. If one is found we make a note of the file that is required so we know to include it in the final bundle. The regex has flaws and doesn’t catch all cases of require calls. The case you mention above is one of them. Sorry about that.

ou, ok.
Strange that the same code works fine in other place

Are you using the require the same way everywhere for the module in question? As long as you require the module once in a way that the builder can detect then you can require it in other ways elsewhere. But if you require the module only once and that’s done the “wrong way” then the .lua file will not be included in the build.

1 Like

now i understood, thx!