Posh-git: Posh-git not loaded because no valid module file found

Created on 20 Jan 2020  路  5Comments  路  Source: dahlbyk/posh-git

System Details

  • posh-git version/path: (this is the issue)
  • PowerShell version: 6.2.3 (PowerShell Core)
  • Git version: 2.25.0.windows.1
  • Operating system name and version: Windows 10.0.18362

Issue Description

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?

Most helpful comment

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.

All 5 comments

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\, particularly C:\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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robianmcd picture robianmcd  路  8Comments

nairby picture nairby  路  6Comments

wsmelton picture wsmelton  路  4Comments

ExE-Boss picture ExE-Boss  路  8Comments

codedog picture codedog  路  7Comments