Skip to content

Importing PowerHTML module in a directory with a Types folder containing multiple .ps1xml files fails #8

Open

Description

@forevanyeung

I'm using PowerHTML is one of my modules, my module contains a Types folder with multiple .ps1xml files. When I am in my module's root directory and try to import the PowerHTML module, it fails with this error:

PS /Users/evan.yeung/git/OktaPS> Import-Module PowerHTML
Import-Module: The member 'FormatsToProcess' in the module manifest is not valid: The path cannot be processed because it resolved to more than one file; only one file at a time can be processed.. Verify that a valid value is specified for this field in the '/Users/evan.yeung/.local/share/powershell/Modules/PowerHTML/0.1.7/PowerHTML.psd1' file.

Activity

  1. forevanyeung commented on Oct 16, 2022

    @forevanyeung
    Author

    Submitted a PR that removes the wildcard matching in FormatsToProcess which fixes the problem.

    Another alternative that will dynamically update format data for all files in the Types folder is adding the below code to the psm1 file.

    #Append format data to session
    $ModuleFormats = @( Get-ChildItem -Path $PSScriptRoot\Types\*.ps1xml -ErrorAction SilentlyContinue )
    foreach ($t in $ModuleFormats)
    {
        Write-Verbose "Appending format data: $($t.FullName)"
        Update-FormatData -Append $t
    }
    

    However, during my testing, this does not clean up after removing the module. So I opted to go for statically defining the format files.

    PS /Users/evan.yeung/git/PowerHTML> get-formatdata | Where-Object { $_.TypeNames -like "*HtmlAgilityPack*" }
    PS /Users/evan.yeung/git/PowerHTML> import-module ../../git/PowerHTML/
    PS /Users/evan.yeung/git/PowerHTML> get-formatdata | Where-Object { $_.TypeNames -like "*HtmlAgilityPack*" }
    
    TypeNames                         FormatViewDefinition
    ---------                         --------------------
    {HtmlAgilityPack.HtmlNode}        {HtmlAgilityPack.HtmlNode}
    {HtmlAgilityPack.HtmlTextNode}    {HtmlAgilityPack.HtmlNode}
    {HtmlAgilityPack.HtmlCommentNode} {HtmlAgilityPack.HtmlNode}
    
    PS /Users/evan.yeung/git/PowerHTML> remove-module powerhtml
    PS /Users/evan.yeung/git/PowerHTML> get-formatdata | Where-Object { $_.TypeNames -like "*HtmlAgilityPack*" }
    
    TypeNames                         FormatViewDefinition
    ---------                         --------------------
    {HtmlAgilityPack.HtmlNode}        {HtmlAgilityPack.HtmlNode}
    {HtmlAgilityPack.HtmlTextNode}    {HtmlAgilityPack.HtmlNode}
    {HtmlAgilityPack.HtmlCommentNode} {HtmlAgilityPack.HtmlNode}
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions