Posh-git: $PSModulePath: The specified module was not loaded

Created on 1 Feb 2017  路  14Comments  路  Source: dahlbyk/posh-git

Running Add-PoshGitToPrompt (via install.ps1 or directly) is correctly finding my posh-git clone in $PSModulePath (and inserting Import-Module posh-git instead of an absolute path), but that Import-Module posh-git call fails with:

```
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
  • ~~~~~~~

    • CategoryInfo : ResourceUnavailable: (posh-git:String) [Import-Module], FileNotFoundException

    • FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

      ```

powershell_2017-02-01_08-59-42

Any ideas to troubleshoot, @rkeithhill?

System Details

  • posh-git version: 33ed60210eb2aef7c6b6c49e7d735db341ae5efc
  • PowerShell version: 5.1.14393.693
  • git version 2.7.1.windows.2
  • OS: Microsoft Windows NT 10.0.14393.0

Most helpful comment

Does your home dir name really have a space in it? I could see how that might cause PS to have issues loading modules. What do you get when you execute $env:PSModulePath. Also, try to specify the full path to the module like so:

import-module "$HOME\Documents\WindowsPowerShell\Modules\posh-git\<version-number>\posh-git.psm1"

All 14 comments

I think Import-Module is looking for a particular directory scheme <module-name>[module-version] under each path in PSModulePath. Another reason why I rarely mess with PSModulePath. :-) This is in my profile:

Import-Module ~\GitHub\dahlbyk\Posh-Git\src\posh-git.psd1

If you remove C:\Dev\OSS\posh-git\src from PSModulePath and remove the import command from your profile, then impo from C:\Dev\OSS\posh-git\src and then run Add-PoshGitToProfile, it should use the full path.

Yep, that's it. Moving the module into src/ means a normal posh-git clone no longer matches the expected pattern. Few options:

  1. Move src/* to src/posh-git/*
  2. Skip our $PSModulePath check if (SplitPath $ModuleBasePath -Leaf) -eq 'src'
  3. Add a Get-Module posh-git -ListAvailable sanity check after a $PSModulePath match

Leaning toward 2锔忊儯

I think we should leave in the PSModulePath to handle the normal install-module install. Before that check we could check for current dir of src and/or ../.git and then import by path. That would cover the git clone case.

Hello,

I have PS version 2. Hence, am using Chocolatey to install posh-git. Any ideas how to go about it?
Sorry for being a noob.

Error:

The "=" operator is missing after a named argument.
ERROR: The module to process 'posh-git.psm1', listed in field 'ModuleToProcess' of module manifest 'C:\tools\poshgit\dah
lbyk-posh-git-a4faccd\src\posh-git.psd1' was not processed because no valid module was found in any module directory.

image

@marc88 try renaming the C:\tools\poshgit\dahlbyk-posh-git-a4faccd\src folder from src to posh-git and update your $PROFILE accordingly. In other cases we've seen PowerShell be picky about loading modules if the folder name doesn't match the module name. (Which is really silly behavior, I might add.)

@dahlbyk : Thank you for the solution!
It worked indeed. But, I tried upgrading powershell to v3.0 and I found Import-Module added the module base directly to my profile. That's when I realised what was actually wrong :)

@dahlbyk Followed those steps and worked for me too. Cheers.

image

Where I'm going wrong I'm not able to fix this one, need some help

Does your home dir name really have a space in it? I could see how that might cause PS to have issues loading modules. What do you get when you execute $env:PSModulePath. Also, try to specify the full path to the module like so:

import-module "$HOME\Documents\WindowsPowerShell\Modules\posh-git\<version-number>\posh-git.psm1"

@dahlbyk Hi, what's the outcome of this issue? I've set up posh-git today and found out this issue still persists, at least for choco.
Btw, the last suggestion works too, I've used it myself as it's really the only way to make importing it future-proof.

@Jan-Karasinski What are the contents of your profile - gc $profile and gc $profile.CurrentUserAllHosts? I just tested a choco install of posh-git in a Windows Sandbox instance and got this for $profile contents ($profile.CurrentUserAllHosts didn't exist):

Import-Module 'C:\tools\poshgit\dahlbyk-posh-git-9bda399\src\posh-git.psd1'

And posh-git imported successfully.

@rkeithhill It was empty and I had to modify it manually, with the full path. Also, my PowerShell env was fresh, I was using it just to execute simple commands that were not requiring any kind of modifications/privileges.

@Jan-Karasinski So you up and running with posh-git?

@rkeithhill Yep, it works like a charm.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ExE-Boss picture ExE-Boss  路  8Comments

exbuzz picture exbuzz  路  7Comments

ewgoforth picture ewgoforth  路  8Comments

GameOverture picture GameOverture  路  5Comments

Patabugen picture Patabugen  路  8Comments