inconsistent `require` behavior when files imported by other mods

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
GlassBricks
Inserter
Inserter
Posts: 25
Joined: Fri Jun 11, 2021 5:20 pm
Contact:

inconsistent `require` behavior when files imported by other mods

Post by GlassBricks »

When a file is imported using "__modname__.path.to.file", the behaviour of "require" within that file changes (vs a "normal" require).
Based on my observations:

If the file is in the root of the mod directory, relative imports do not work at all.
If the file is in a folder, relative imports are searched for in the folder rather than the root of the mod directory. E.g. inside "mod1/folder/foo.lua", a require("bar") tries to look for "__mod1__/folder/bar.lua". whereas normally it would search for "__mod1__/bar.lua"

This seems like very weird behaviour.

If this is intentional, this could be added to documentation
If this is not intentional... I guess this is a bug report.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13204
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: inconsistent `require` behavior when files imported by other mods

Post by Rseding91 »

See: 67032
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding interface requests”