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

sv in windows powershell conflicts with Set-Variable #317

Open
Paillat-dev opened this issue Nov 18, 2024 · 17 comments
Open

sv in windows powershell conflicts with Set-Variable #317

Paillat-dev opened this issue Nov 18, 2024 · 17 comments
Labels
bug Something isn't working

Comments

@Paillat-dev
Copy link

In powershell, sv is an alias to Set-Variable. Thus I cannot use npx sv as that conflicts with the alias which takes precedence. And the alias can for some reason not be removed, when I remove it with Remove-Item Alias:sv -Force it comes back directly afterwards.

How can I use npx sv then ?

@jackvanderbilt-visma
Copy link

This does not happen in my powershell, and shouldn't happen in any; though I am not using PowerShell v7. Can you share a screenshot of your terminal running just npx sv, or just the logs nicely formatted?

@Paillat-dev
Copy link
Author

image

@jackvanderbilt-visma
Copy link

jackvanderbilt-visma commented Nov 18, 2024

Try npx "sv" instead

@Paillat-dev
Copy link
Author

same thing
image

@manuel3108
Copy link
Member

manuel3108 commented Nov 18, 2024

This is strange. I'm developing sv on a daily basis on Windows inside Powershell, and never experienced this. Also you are the first person reporting since the tool was published about 30 days ago.

I'm not saying the problem does not exist, I'm just trying to explain that this seems to be some kind of edge case and not a global problem.

Also I'm not sure why ps kicks in for something that is obviously not the first argument.

Edit: Relates #259

@Paillat-dev
Copy link
Author

I also had it working just fine and at some point it just broke and started doing this. I don't think I installed anything that would have changed that either.

@Paillat-dev
Copy link
Author

Paillat-dev commented Nov 18, 2024

Also, unlike the related issue you mentioned, running npx sv@latest doesn't change anything.

@Paillat-dev
Copy link
Author

Currently, to use sv I had to install it globally with npm then use C:\Users\Jérémie\AppData\Roaming\npm\sv

@manuel3108
Copy link
Member

Could you please run $PSVersionTable and paste the result? This is the result for me

Name                           Value
----                           -----
PSVersion                      5.1.22621.4391
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.4391
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

@Paillat-dev
Copy link
Author

Sure:

Name                           Value
----                           -----
PSVersion                      5.1.22621.4249
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.4249
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

@jackvanderbilt-visma
Copy link

jackvanderbilt-visma commented Nov 20, 2024

Could it be that npx just defaults to running sv because it can't find the sv package on your system? Somehow that this is configured npx behavior on your system or something similar?

What happens when you npm install sv -g and then try npx sv? just saw your previous response, so nevermind this question.

@manuel3108 manuel3108 added the bug Something isn't working label Nov 29, 2024
@danxcraig
Copy link

As far as I'm aware (I could be wrong), built in cmdlets like Set-Variable take precedence.

I think some versions of PowerShell look for built-in commands or aliases before checking external executables. So, since sv is already an alias for Set-Variable, PowerShell immediately interprets and runs that command instead of passing it to npx like it should.

If I'm right (can't test), you might be able to resolve the issue by running either npx -- sv or & npx sv. If either of those work, I have a feeling this might be less a bug, more just a quirk that needs to be documented.

@Paillat-dev
Copy link
Author

Paillat-dev commented Dec 11, 2024

Unfortunately the issue is not fixed by npx -- sv nor & npx sv.

I noticed that the issue dosen't happen with pnpm dlx sv.

This seems to be expected behaviour according to this, specifically:

If any requested packages are not present in the local project dependencies, then a prompt is printed, which can be suppressed by providing either --yes or --no. When standard input is not a TTY or a CI environment is detected, --yes is assumed. The requested packages are installed to a folder in the npm cache, which is added to the PATH environment variable in the executed process.

The above may imply that it is added to path, then the command executed, which would lead to Set-Variable taking precedence in the path.

@danxcraig
Copy link

danxcraig commented Dec 11, 2024

So strange! Couple of other ideas:

  1. If you notepad $PROFILE then add Remove-Item Alias:sv -Force -ErrorAction SilentlyContinue, close and reopen powershell, does that resolve the issue? (if so, that'll at least confirm that it is a precedence issue).
  2. If not, any joy via npm exec instead of npx?
  3. If not, what's your npx -v and node -v?

@Paillat-dev
Copy link
Author

Remove-Item Alias:sv -Force -ErrorAction SilentlyContinue in the profile does fix the issue !

@danxcraig
Copy link

Remove-Item Alias:sv -Force -ErrorAction SilentlyContinue in the profile does fix the issue !

Wahoo!

@Paillat-dev
Copy link
Author

Now idk if that's considered a workaround or a valid fix for this issue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants