I am experiencing a problem with trying to import posh-git. I already have posh-git installed, using Chocolatey. (I tried installing it again using Chocolatey; Chocolatey complained informing me that I already had it installed.) Then I tried issuing the Import-Module posh-git command to import posh-git, so I can use it. However, when I do I get this error:
Import-Module : The specified module 'posh-git' was not loaded because no valid module file was found in any module directory.
At line:1 char:1
- Import-Module posh-git
~~~~
undException- FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModule Command
This confuses me. Is it installed or not?
PowerShell's Import-Module only looks in specific locations for PowerShell modules. You can see those locations in $env:PSModulePath. If the module is not installed in one of those locations, it won't be found during import. You have two options: 1) add the install path - wherever choco put the module in the PSModulePath env var or 2) use PowerShell's built-in command to install the module: Install-Module posh-git -Scope CurrentUser -Force -AllowClobber -AllowPrerelease.
@rkeithhill how do I find out where posh-git is installed?
Look under C:\ProgramData\chocolatey\, particularly C:\ProgramData\chocolatey\lib.
I forgot to mention, another option is to use the full path to posh-git.psd1 e.g. Import-Module <full-path-posh-git.psd1>
Look under
C:\ProgramData\chocolatey\, particularlyC:\ProgramData\chocolatey\lib.
More specifically, we use Get-ToolsLocation:
https://github.com/dahlbyk/posh-git/blob/f69efd9229029519adb32e37a464b7e1533a372c/chocolatey/tools/chocolateyInstall.ps1#L2
Which there's been some discussion about: https://github.com/dahlbyk/posh-git/issues/473.
I'm going to go ahead and close this; please reopen if you're still not able to resolve this.
Most helpful comment
PowerShell's
Import-Moduleonly looks in specific locations for PowerShell modules. You can see those locations in$env:PSModulePath. If the module is not installed in one of those locations, it won't be found during import. You have two options: 1) add the install path - wherever choco put the module in the PSModulePath env var or 2) use PowerShell's built-in command to install the module:Install-Module posh-git -Scope CurrentUser -Force -AllowClobber -AllowPrerelease.