Search code examples
node.jspowershellserverless-framework

Serverless Framework sls Conflicts with Powershell sls (Select-string)


I installed the Serverless Framework using the following NPM command

npm install -g serverless

When I try to run the serverless command sls in Powershell, I get a strange result which mentions "cmdlet Select-string".

sls --version

enter image description here

Can someone help me with this issue?


Solution

  • It seems that PowerShell has a command/cmdlet called Select-String which has an alias of sls. The PowerShell alias sls seems to take precedence over the node.js serverless command of sls.

    One way to remove the PowerShell sls alias is by running the following in PowerShell

    Remove-Item alias:sls
    

    This change only applies to the current PowerShell session.

    To permanently the sls PowerShell alias, you can change Microsoft.PowerShell_profile.ps1 file.

    From PowerShell open your profile page in Notepad with the following command:

    notepad $profile
    

    Add the following to the file and save.

    remove-item alias:sls
    

    The profile can be reloaded by running the following from Powershell

    . $profile
    

    In my file, you will see that I have removed the aliases of curl and sls.

    Change PowerShell Profile

    Now I see what I expect when entering sls in PowerShell. enter image description here

    How do I permanently remove a default Powershell alias?

    --- Update ----

    A more simple option is to use the command "serverless" instead of "sls".