-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Labels
Bugthing that needs fixingthing that needs fixingNeeds Triageneeds review for next stepsneeds review for next steps
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
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.
Metadata
Metadata
Assignees
Labels
Bugthing that needs fixingthing that needs fixingNeeds Triageneeds review for next stepsneeds review for next steps