Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 215
Mike Barlow - BarDev Avatar asked Apr 09 '17 03:04

Mike Barlow - BarDev


2 Answers

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".

like image 124
Mike Barlow - BarDev Avatar answered Sep 19 '22 12:09

Mike Barlow - BarDev


For future visitors - in current version (if serverless is installed by npm/yarn) ^1.61 there is a secondary shortcut option:

slss

and that shortcut works flawlessly in Powershell. Imo it's the simplest way to avoid problems with Select-String alias collision and do not require any change in Powershell session or config.

PS C:\htdocs\serverless> slss -v
Framework Core: 1.61.1
Plugin: 3.2.7
SDK: 2.2.1
Components Core: 1.1.2
Components CLI: 1.4.0

If serverless is installed by chocolatey (as mentioned by @Nick Cox in comment) slss approach will fail, and you can use approach suggested by him - sls.exe

like image 40
grexlort Avatar answered Sep 20 '22 12:09

grexlort