Skip to content

The specified module 'Dotenv' was not loaded because no valid module file was found in any module directory. #16

Description

@brian6932

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

I tried with and without a leading:

Import-Module DotEnv

I have DotEnv installed through scoop (~/scoop/modules in my $env:PSModulePath), so it shouldn't require any imports in the first place, using this manifest: https://github.com/insomnimus/scoop-bucket/blob/main/bucket/ps-dotenv.json.

This is the offending block of code in my $PROFILE:

Enable-Dotenv

If I put it before Import-ProfileAsync, it works, and causes no problems with $Dotenv usages after.

Expected behavior

Well I expect Enable-Dotenv to work in the block, either with or without an import. This isn't a huge deal, it only takes 30-40ms on my PC anyway.

It's not really clear to me how this module functions with $env:PSModulePaths (since they don't often need imports), one race condition I noticed was that I would have to explicitly run Import-Module PSFzf, or else that PSModule wouldn't be loaded in time for the Set-PsFzfOptions I have in my $PROFILE... This is getting off topic, so I'll make a separate issue about this if required.

Actual behavior

DotEnv functions are imported into the shell, yet I get this error on launch:

Import-Module: ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1:12
Line |
  12 |      Import-Module Dotenv
     |      ~~~~~~~~~~~~~~~~~~~~
     | The specified module 'Dotenv' was not loaded because no valid module file was found in any module directory.

Enable-Dotenv: ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1:14
Line |
  14 |      Enable-Dotenv
     |      ~~~~~~~~~~~~~
     | The term 'Enable-Dotenv' is not recognized as a name of a cmdlet, function, script file, or executable program.
     | Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

InvalidOperation: ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1:15
Line |
  15 |      $Dotenv.SafeMode = $false
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~
     | The property 'SafeMode' cannot be found on this object. Verify that the property exists and can be set.

InvalidOperation: ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1:16
Line |
  16 |      $Dotenv.Quiet = $true
     |      ~~~~~~~~~~~~~~~~~~~~~
     | The property 'Quiet' cannot be found on this object. Verify that the property exists and can be set.

Error details

It's pretty much the same as the launch error.

Environment data

❯ [System.Environment]::OSVersion

Platform ServicePack Version      VersionString
-------- ----------- -------      -------------
 Win32NT             10.0.19044.0 Microsoft Windows NT 10.0.19044.0


❯ Get-Module

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     0.0                   chocolateyProfile                   {Update-SessionEnvironment, refreshenv}
Script     1.0.2                 Dotenv                              {Read-Dotenv, Add-DotenvPattern, Approve-DotenvDir, Approve-DotenvFile…}
Script     1.9.4                 man-highlighting                    Get-Help
Manifest   7.0.0.0               Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Binary     2.2.0                 Microsoft.PowerShell.ThreadJob      Start-ThreadJob
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script     0.4.2                 ProfileAsync                        Import-ProfileAsync
Script     2.7.9                 PSFzf                               {Enable-PsFzfAliases, Invoke-FuzzyEdit, Invoke-FuzzyFasd, Invoke-FuzzyGitStatus…}
Script     0.0                   PSLazyCompletion
Script     2.2.0      beta4      PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler…}
Script     0.11.0                Terminal-Icons                      {Add-TerminalIconsColorTheme, Add-TerminalIconsIconTheme, Format-TerminalIcons, Get-TerminalIconsColorTheme…}

❯ pwsh -V
PowerShell 7.6.0-rc.1

Visuals

No response

Activity

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