Why aren’t local required modules loading from a manifest in PowerShell 5.1?

0
5
Asked By MellowHarbor42 On

I'm building a test module with a manifest named Template.psd1. The manifest lists three .psm1 files under a Control subfolder, alongside the manifest and the main module file:

RequiredModules = @(
'Control\ControlMessaging.psm1',
'Control\ControlChecklist.psm1',
'Control\ControlPrompt.psm1'
)

Importing the manifest with PowerShell 7.4 works, but PowerShell 5.1 reports that Control\ControlMessaging.psm1 could not be found in any module directory. Adding .\ to the paths produces the same error. I need the module to work in both PowerShell versions. Is this a limitation or known path-handling issue in Windows PowerShell 5.1, and what is the correct way to structure these local dependencies?

3 Answers

Answered By QuietOrbit58 On

For RequiredModules, PowerShell 5.1 expects module specifications rather than arbitrary relative paths to individual .psm1 files. A manifest path can work when it is fully qualified, but using local .psm1 files this way is generally unreliable. If these are part of your project, import them from the main .psm1 file instead, using paths based on the module’s directory.

NorthwindEcho6 -

The important distinction is that RequiredModules is intended for dependencies discoverable through PSModulePath, not usually for private files sitting beside your module.

Answered By CopperLark7 On

This is a known limitation in Windows PowerShell 5.1. Its RequiredModules handling does not reliably resolve relative paths to local .psm1 files. Later PowerShell versions improved this behavior. Adding .\ usually does not fix it.

BrightCedar19 -

That matches what I found too. PowerShell 5.1 still reports that the module cannot be found even when the path starts with .\.

Answered By SilverMaple31 On

Since the Control files are bundled with your module, they are better treated as nested modules rather than external required modules. You can import them from the main Template.psm1 using a path built from the module directory, then export whichever functions or aliases should be public. This avoids relying on the broken relative-path behavior in 5.1.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.