Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
If PowerShell's strict mode is turned on, npm.ps1 fails. Steps to reproduce:
- Open Windows PowerShell 5.1. Make sure npm.ps1 is in your path, i.e. that
Get-Command npm.ps1 returns a value.
- Run
Set-StrictMode -Version 'Latest' ; npm.ps1 version.
- Note the errors about missing properties: "ERROR: The property 'Statement' cannot be found on this object. Verify that the property exists."
Update npm.ps1 to support strict mode. It must check if properties exist before using them. The Statement property on $MyInvocation exists in PowerShell 7, but not Windows PowerShell 5.1.
Expected Behavior
I expect no errors and npm.ps1 to not fail when run in strict mode. I recommend adding Set-StrictMode -Version 'Latest' in npm.ps1.
Steps To Reproduce
- Open Windows PowerShell 5.1. Make sure npm.ps1 is in your path, i.e. that
Get-Command npm.ps1 returns a value.
- Run
Set-StrictMode -Version 'Latest' ; npm.ps1 version.
- Note the errors about missing properties: "ERROR: The property 'Statement' cannot be found on this object. Verify that the property exists."
Environment
- npm: 11.4.2
- Node.js: v.24.4.1
- OS Name: Windows 10
- System Model Name: Lenovo ThinkPad P15v Gen 3
- npm config:
; "user" config from C:\Users\********\.npmrc
@********:registry = "https://********/"
registry = "https://********"
; node bin location = C:\Build\********\.node\node.exe
; node version = v24.4.1
; npm local prefix = C:\********
; npm version = 11.4.2
; cwd = C:\********
; HOME = C:\Users\********
; Run `npm config ls -l` to show all defaults.
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
If PowerShell's strict mode is turned on, npm.ps1 fails. Steps to reproduce:
Get-Command npm.ps1returns a value.Set-StrictMode -Version 'Latest' ; npm.ps1 version.Update npm.ps1 to support strict mode. It must check if properties exist before using them. The
Statementproperty on$MyInvocationexists in PowerShell 7, but not Windows PowerShell 5.1.Expected Behavior
I expect no errors and npm.ps1 to not fail when run in strict mode. I recommend adding
Set-StrictMode -Version 'Latest'in npm.ps1.Steps To Reproduce
Get-Command npm.ps1returns a value.Set-StrictMode -Version 'Latest' ; npm.ps1 version.Environment