When a script module is loaded from a package, the ScriptPackage calls ScriptModule.loadModule() to initialise it.
However, if a root script module (e.g. ‘foo’ instead of ‘app.foo’) is added using ScriptManager.addScriptModule(), that module’s loadModule method will never be called, as it isn’t being loaded from a package. This means that no functions or properties are set on the module object so it’s empty until loadModule() is called manually.
I can see two possible fixes for this:
- Load root modules as soon as they are added. This is probably a bad idea. Error handling for this could be very difficult. Also, if this module depends on other modules it’s likely that they may not have been added yet.
- Change ScriptModule.findattr to load the module first if it has not already been loaded.