Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import-module not working in v2.6.2 #965

Closed
crackermania opened this issue May 11, 2022 · 3 comments · Fixed by #971
Closed

Import-module not working in v2.6.2 #965

crackermania opened this issue May 11, 2022 · 3 comments · Fixed by #971
Assignees
Labels
Milestone

Comments

@crackermania
Copy link

Hi,

I'm tested v2.6.2 missing capabilities to import-module ps1 file. It's working fine in v2.4.2 and 2.5.2. My code as per below :

Import-Module -Name Pode -RequiredVersion 2.6.2

get-module Pode | Out-Default 

#1) not working
#Import-Module "D:\Scripts\testModule.ps1" -Scope Global
#2) not working in 2.6.2, work well in 2.4.2 and 2.5.2
Import-Module "D:\Scripts\testModule.ps1"

Start-PodeServer -Threads 2{

    Add-PodeEndpoint -Address * -Port 8200 -Protocol Http

    Add-PodeRoute -Method Get -Path 'api' -ScriptBlock {		
	#3) not working
        #Import-Module "D:\Scripts\testModule.ps1"
        ("Inside ThreadId: {0}" -f $ThreadId) | Out-Default 	
		$test = randomTaskID
		Write-PodeJsonResponse -Value @{ 'value' = "$test" }
		
    }

    New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging

}

testModule.ps1 contain code as per below :

function randomTaskID
{
	$taskID = Get-Random -Minimum 1000 -Maximum 99999999
	return $taskID
}

Consider bug or expected behavior for latest release?

By the way, it's working well if i paste the function before Start-PodeServer.

Thanks.

@Badgerati
Copy link
Owner

Hi @crackermania,

This could be a bug actually for .ps1 files, the logic for importing modules was tweaked in 2.6.0.

What happens if you change the file to be .psm1 instead?

@crackermania
Copy link
Author

@Badgerati ,

Thanks.. I can confirmed, I can use after change to psm1.

From : https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module?view=powershell-7.2

-Name

Specifies the names of the modules to import. Enter the name of the module or the name of a file in the module, such as a .psd1, .psm1, .dll, or .ps1 file. File paths are optional. Wildcard characters aren't permitted. You can also pipe module names and filenames to Import-Module.

So, consider bug? Thanks.

@Badgerati
Copy link
Owner

@crackermania,

Since it used to work pre-2.6.0, and the docs say it should work for ps1 files then yes, it's a bug. Though it seems there's a workaround for now if changing the extension to psm1 works.

Badgerati added a commit that referenced this issue May 30, 2022
@Badgerati Badgerati self-assigned this May 30, 2022
@Badgerati Badgerati added this to the 2.7.0 milestone May 30, 2022
@Badgerati Badgerati mentioned this issue Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants