fix: rename $Args to $InstallArgs in install.ps1 for Windows#478
Open
vaibhavkumar779 wants to merge 1 commit into
Open
fix: rename $Args to $InstallArgs in install.ps1 for Windows#478vaibhavkumar779 wants to merge 1 commit into
vaibhavkumar779 wants to merge 1 commit into
Conversation
…ility
$Args is a PowerShell automatic variable that cannot be overwritten inside
Invoke-Expression. When users run irm ... | iex, PowerShell throws:
Cannot overwrite variable Args because the variable has been optimized.
This rename to $InstallArgs fixes the parameter conflict. The README and
INSTALL.md are also updated to use the download-then-run pattern which avoids
Invoke-Expression scope issues entirely.
Tested on Windows 11 with PowerShell 5.1 and VS Code GitHub Copilot agent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
install.ps1uses$Argsas aparam()name, but$Argsis a PowerShell automatic variable that cannot be overwritten insideInvoke-Expression. When users run the documented one-liner:PowerShell throws:
This breaks the install on every Windows machine using PowerShell 5.1 (the default shell).
Why it happens
When a script is piped to
Invoke-Expression, PowerShell compiles the script block in the caller's scope. The automatic$Argsvariable is marked as an optimized/read-only variable in that context, soparam([string[]]$Args)fails because it tries to reassign it.Running the script as a file (
& .\install.ps1) works fine because it gets its own scope — but that defeats the purpose of the one-liner install.Environment
Fix
1.
install.ps1— Rename parameter (3 occurrences)[string[]]$Args[string[]]$InstallArgs@Args(splat in local path)@InstallArgs@Args(splat in npx path)@InstallArgsAlso updated the header comment to use the download-then-run pattern and added a
NOTEblock explaining why$Argscannot be used.2.
README.md— Updated Windows install command3.
INSTALL.md— Updated install command + troubleshootingirm | iextroubleshooting bullet with an explicit warning and the correct commandTesting
irm ... | iex→ crashes withVariableNotWritableRare%TEMP%, runs in own scope, installs successfully, cleans up temp file& .\install.ps1still works (no regression)Checklist
$Args→$InstallArgsininstall.ps1(all 3 occurrences)install.shuntouched)& .\install.ps1still works)