Why does RequiredModules fail to load local .psm1 files in PowerShell 5.1?

August 30, 2026 3 answers
Asked by MellowPine42
I'm building a test module with a manifest named Template.psd1 and a module file in the same directory. The manifest declares several local module files under a Control subfolder as required modules: RequiredModules = @( 'Control\ControlMessaging.psm1', 'Control\ControlChecklist.psm1', 'Control\ControlPrompt.psm1' ) The files exist beside the manifest in the Control directory. Importing the manifest works in PowerShell 7.4, but PowerShell 5.1 reports that Control\ControlMessaging.psm1 could not be found in any module directory. Using .\ prefixes produces the same result. I need the module to work in both PowerShell 5.1 and 7.4. What is the correct way to handle these local dependencies?

Answers

CobaltWren8
PowerShell 5.1 has known path-handling problems with RequiredModules. In that version, a local .psm1 path generally isnโ€™t handled correctly as a required module. A .psd1 can work, but it needs to use a fully qualified path. Later PowerShell versions improved this behavior.

MellowPine42: That explains the difference between the two versions. Thanks for clarifying!

Reply to this answer
SilverMaple63
RequiredModules is primarily intended for dependencies that are installed as modules and discoverable through PSModulePath, such as separately published modules. For local files bundled with your project, importing them from the main .psm1 is usually more compatible with Windows PowerShell 5.1. Adding .\ to the RequiredModules entries wonโ€™t avoid the underlying 5.1 limitation.
Reply to this answer
QuietHarbor17
If these Control files are part of your module rather than external dependencies, RequiredModules probably isnโ€™t the right mechanism. Import them from Template.psm1 with Import-Module using paths based on the moduleโ€™s location, or structure them as nested modules. Imports performed inside the module run in its module scope, and you can explicitly export anything that should be exposed publicly.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions