Repository navigation
Closed
Labels
Milestone
Description
If I modify the PSModulePath, it causes errors on practically every module load.
Steps to reproduce
pwsh -noprofile
# Add a new, folder to the PSModulePath. This one is empty. It doesn't have to be.
$Env:PSModulePath += ";" + $(mkdir TestModules | cvpa)
# Try to import a module that's already imported
import-module Microsoft.PowerShell.Management
# Try to import a new module
import-module Microsoft.PowerShell.Diagnostics
# List the imported modules:
Get-Module
Expected behavior
Silent success
Actual behavior
No matter what module you load, you get an error message. For instance:
import-module : The specified module 'Microsoft.PowerShell.Management' was not loaded because no valid module file was
found in any module directory.
At line:1 char:1
+ import-module Microsoft.PowerShell.Management
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (Microsoft.PowerShell.Management:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Note: the module is loaded, but the error message indicates that it was not. This applies to modules that were already loaded as well as importing new modules -- you get a big error, but it appears that the module import is actually working behind the scenes: Get0Mo
Environment data
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0-beta.9
PSEdition Core
GitCommitId v6.0.0-beta.9
OS Microsoft Windows 10.0.15063
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Reacted by Friedrich von Never
Reacted by Christoph Bergmeister, Nate Ferrell, Thomas Rayner and Kagami Sascha Rosylight
Activity
SteveL-MSFT commentedon Oct 25, 2017
With some code refactoring to support case-insensitive module loading on non-Windows, the loop looking for the module wasn't breaking after it found the module so even though it loaded the module, it thinks it wasn't found so it reports an error.
doxxx commentedon Dec 22, 2017
I'm still seeing this problem on Linux with powershell 6.0.0-rc.2.
I have a build script that updates
$env:PSModulePathto add a directory containing custom modules. Let's call this/path/to/custom/modules. So my PSModulePath looks like:The directory structure looks like this:
When I try
Import-Module CompanyName\Git(orCompanyName/Git), I get the error as described in the OP. I also triedCompanyName\Git\GitandCompanyName\Git\Git.psm1.However, this works:
Import-Module /path/to/custom/modules/CompanyName/Git/Git.psm1If I move
Git.psm1to/path/to/custom/modules/Git/Git.psm1, thenImport-Module Gitworks.So I'm guessing that the namespace subfolders behaviour of Powershell 5.1 on Windows no longer works in Powershell Core 6. If I use "CompanyName.Git" as the folder name and psm1 filename, then it works. I'm happy with this as a solution.
MaximoTrinidad commentedon Dec 22, 2017
Interesting! For many years I have assume adding the custom Module folder to the PSmodulePath then the actual module folder name is the one containing the PSD1 and PSM1 files. I have always kept it simple!
:)

iSazonov commentedon Dec 22, 2017
Gordon Tyler (@doxxx) Feel free open new Issue if you believe that this behavior is useful.
doxxx commentedon Dec 22, 2017
Ilya (@iSazonov) I think it's fine. Just initially confusing coming from PowerShell 5.1. It may be something to note in a migration guide or other documentation.
Jaykul commentedon Dec 23, 2017
You were never supposed to nest them ... except for version number folders. The other thing is a major perf bug in PS5