Skip to content

Major module loading problems in beta 9 #5232

Closed

Description

@Jaykul

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.0

Activity

  1. added
    WG-Engine
    on Oct 25, 2017
  2. added this to the milestone on Oct 25, 2017
  3. SteveL-MSFT commented on Oct 25, 2017

    @SteveL-MSFT
    Member

    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.

  4. doxxx commented on Dec 22, 2017

    @doxxx

    I'm still seeing this problem on Linux with powershell 6.0.0-rc.2.

    I have a build script that updates $env:PSModulePath to add a directory containing custom modules. Let's call this /path/to/custom/modules. So my PSModulePath looks like:

    /home/myuser/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/6.0.0-rc.2/Modules:/path/to/custom/modules
    

    The directory structure looks like this:

    /path/to/custom/modules
    - CompanyName
      - Git
        - Git.psm1
    

    When I try Import-Module CompanyName\Git (or CompanyName/Git), I get the error as described in the OP. I also tried CompanyName\Git\Git and CompanyName\Git\Git.psm1.

    However, this works: Import-Module /path/to/custom/modules/CompanyName/Git/Git.psm1

    If I move Git.psm1 to /path/to/custom/modules/Git/Git.psm1, then Import-Module Git works.

    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.

  5. MaximoTrinidad commented on Dec 22, 2017

    @MaximoTrinidad

    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!

    :)
    linuxcustommodules_2017-12-22_11-53-31

  6. iSazonov commented on Dec 22, 2017

    @iSazonov
    Collaborator

    Gordon Tyler (@doxxx) Feel free open new Issue if you believe that this behavior is useful.

  7. doxxx commented on Dec 22, 2017

    @doxxx

    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.

  8. Jaykul commented on Dec 23, 2017

    @Jaykul
    ContributorAuthor

    You were never supposed to nest them ... except for version number folders. The other thing is a major perf bug in PS5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Resolution-FixedWG-Engine

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions