Repository navigation
Test-ModuleManifest working sporadically on v6.1.0-preview.2 #6818
Description
Activity
- addedIssue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the product
on May 4, 2018 This is not a recent regression. It repros in PS Core 6.0.1.
Test-ModuleManifest : The module manifest 'MyModule.psm1' could not be processed because it is not a valid PowerShell module manifest file.
Lars Bing Bong. (@larssb) I tried your
.psd1on my machine, and it failed because itTest-ModuleManifestcannot find the root module fileMyModule.psm1. The fact that you observe this failure inconsistently might suggest that theMyModule.psm1file is not deployed by the "build" task whenTest-ModuleManifestruns.But I do think the behavior of
Test-ModuleManifestis not right in this case, see it's result:PS:13> Test-ModuleManifest .\test.psd1 Test-ModuleManifest : The module manifest 'MyModule.psm1' could not be processed because it is not a valid PowerShell module manifest file. Remove the elements that are not permitted: F:\tmp\test.psd1 At line:1 char:1 + Test-ModuleManifest .\test.psd1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (.\test.psd1:String) [Test-ModuleManifest], ArgumentException + FullyQualifiedErrorId : Modules_InvalidRootModuleInModuleManifest,Microsoft.PowerShell.Commands.TestModuleManifestCommand ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Binary 0.0.12 test {Add-ScheduledTask, get-environmentOS, get-hostname, Get-P...The error message should be improved to mention it could be the file is not found. And, should that be an terminating error? The returned result incorectly indicates the module is a binary module ...
Reacted by Michael KlementThank you for troubleshooting and sorry for the late reply.
Hmm...:
- The *.psm1 file is included in the build output.
In order to correctly test it don't you have to:
- Have a folder named as the module. So have the "MyModule.psm1" file in a folder named MyModule. And also have the .psd1 file named MyModule.psd1 as well.
And agree any error message improvements, and those can be had, would be great.
Thank you.
Reacted by Michael KlementAny news on this?
Reacted by Marc KassayDongbo Wang (@daxian-dbw), I'm experiencing similar behavior, if not the same as Lars Bing Bong. (@larssb) has mentioned. Currently I'm working on PowerShellGet #294 issue for Update-ModuleManifest which uses Test-ModuleManifest internally.
When I'm stepping thru Update-ModuleManifest, I'll introspect the data going into Test-ModuleManifest and it looks good. But the data that it returns is missing or strangely in some cases, reverted to previous values.
After glancing into Test-ModuleManifest source code several times I have a couple of questions.
- What's the need for checking multiple files in the directory of this cmdlet's Path parameter, while it seems to test just one? These comments and if statements.
- Also, Update-ModuleManifest performs several IO operations and in doing so creates a temp file (with .psd1 extension) in the same directory as the file to be updated. Is this something that should be considered risky when using Test-ModuleManifest? Because it seems that Test-ModuleManifest is retrieving data perhaps somewhere else in some cases as Lars Bing Bong. (@larssb) and I have noticed. And risky considering my 1st question.
- And finally, what's the intention of Import-PowerShellDataFile command? Should that be used instead of Test-ModuleManifest for accessing data? I see in PowerShellGet source code that Test-ModuleManifest is used to access data for its output. Which seems weird considering its verb name, 'Test'.
Hopefully that is explained clearly, if not please let me know.
Reacted by Lars Bing Bong., John Zabroski and Michael KlementI believe I have run into this issue on PowerShell v5 and I don't think it's a recent regression. I think it's been buggy since PowerShell v2.
The crux of the problem is the C# code inherits from ModuleCmdletsBase class, which is apparently stateful.
See my bug report in Powershellget here https://github.com/PowerShell/PowerShellGet/issues/321#issuecomment-419614919
Suffice to say, this could be a major security vulnerability.
How do I test against older versions of PowerShell? I believe I can 100% reproduce this issue, and that it is not at all "sporadic" in nature. The issue is that ModuleCmdletBase caches stuff stupidly, and is poorly written and/or doesn't make sense when you're doing local development on a new module.
John Zabroski (@jzabroski) Could you please add simple repo steps?
Reacted by Michael KlementDongbo Wang (@daxian-dbw), Lars Bing Bong. (@larssb): Re improving the error message: please see #6683
Reacted by John ZabroskiIn addition to the debatable behavior mentioned by Dongbo Wang (@daxian-dbw) - that a module-info object is still output even if the specified manifest is invalid - here's a simple reproduction that shows the unexpected statefulness of
Test-ModuleManifestmentioned by John Zabroski (@jzabroski):Setup:
# Create folder 'tmpModule' with a manifest and module of the same name. New-ModuleManifest (Join-Path (New-Item -Force -Type Directory tmpMod) tmpMod.psd1) -RootModule tmpMod.psm1 -function foo 'function foo { "foo" }' > tmpMod/tmpMod.psm1
At this point,
Test-ModuleManifestsucceeds.Test-ModuleManifest tmpMod/tmpMod.psd1 # OK
Now, make the
RootModuleentry invalid and change the version number, and then runTest-ModuleManifestagain:# Note that a RootModule entry without .psm1 extension is *currently* invalid, # even though it shouldn't be - see https://github.com/PowerShell/PowerShell/issues/8388 # Using the same *base name*, however, is a prerequisite for # making the caching problem show. ((Get-Content ./tmpMod/tmpMod.psd1) -replace '^RootModule = .*', 'RootModule = "tmpMod"' -replace '^ModuleVersion = .*', 'ModuleVersion = "0.0.9"') | Out-File ./tmpMod/tmpMod.psd1
Now run
Test-ModuleManifestagain, which should now fail:# !! In the same session: succeeds unexpectedly, due to caching. Test-ModuleManifest tmpMod/tmpMod.psd1
While the output reflects the changed version number, the fact that the
RootModuleentry is now "invalid" was missed - see #8388To verify that the manifest is now indeed invalid, open a new PowerShell session and run the last command again.
Reacted by John ZabroskiIlya (@iSazonov) I don't need to outline repro steps. Just look at how BAD this code is:
PowerShell/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
Lines 345 to 352 in 79f21b4
if (found) { // Cache the module's exported commands after importing it, or if the -Refresh flag is used on "Get-Module -List" if ((module != null) && !module.HadErrorsLoading) { AnalysisCache.CacheModuleExports(module, Context); } } The ONLY way to clear your AnalysisCache is to restart PowerShell.exe - good luck getting rid of bug reports that PowerShell sucks if people cannot reliably build modules in it. I realize this was done to speed up powershell, but I keep pointing out to Microsoft engineers they are going about improving performance the wrong way.
Reacted by Maximilian OrsleyMichael Klement (@mklement0) Thank you. I humbly suggest I owe you a beer, for simply doing your job correctly.
Reacted by Michael Klement12 remaining items
@TheIncorrigible1 DId you read me notes on this issue?
Basically, the issue is that the Module Analysis cache cannot be fully disabled. The only solution is to continuously close and re-open your terminal by creating new sessions / runspaces.
John Zabroski (@jzabroski)
DId you read me notes on this issue?Yes, I read your responses, but the only thing that worked for me was using
Get-Module -Refresh.The only way to clear your module analysis cache is to close your pwsh.exe process. This will terminate the cache, since the cache is in-process and not global to the OS. I'm not sure why
Get-Module -Refreshworked for you - are you able to consistently reproduce that behavior?John Zabroski (@jzabroski) Again, didn't work. None of the remediation worked except what I noted. It wasn't consistent that it resolved the issue; I ended up manually changing the call to the cmdlet to use
Import-PowerShellDataFileinstead.@TheIncorrigible1 I think I see the nuance - in your case, you've installed a module locally, and you are using
Import-Module YourModule -Forceto clear the old module from the local disk cache (as opposed to memory cache)? Do I have it right? I think the painful part for me is that -Verbose on these commands is not helpfulJohn Zabroski (@jzabroski) Please follow Code of Conduct Be respectful.
microsoft-github-policy-service commented
on Nov 16, 2023 ContributorMore actionsThis issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented
on Nov 16, 2023 ContributorMore actionsThis issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented
on Nov 16, 2023 ContributorMore actionsThis issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
- addedResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or more
on Nov 16, 2023 microsoft-github-policy-service commented
on Nov 23, 2023 ContributorMore actionsThis issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.
- addedWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issuesand removed
on Jul 17, 2026
If it is a bug report:
You can install the latest version from https://github.com/PowerShell/PowerShell/releases
Steps to reproduce
N.B. This is a sporadic issue.
Test-ModuleManifestcmdlet against the files that was written via the "build" task. It might fail. However, if I runTest-ModuleManifestagainst the .psd1 file in the root of the repo it might work. And vice versa.Test-ModuleManifestworks on the MyModule.psd1 manifest. Without me chaning anything in the MyModule.psd1 file.Import-Moduleon both the MyModule.psm1 and the MyModule.psd1 files and they successfully import.Test-ModuleManifestsometimes an test successfully and sometimes not.Expected behavior
That
Test-ModuleManifestdoes not throw (as long as you really have a valid manifest file)Actual behavior
Environment data
OS: MacOS
OS v.: 10.13.5 Beta
Any help is appreciated. Thank you very much.