cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] After npm upgrade, on Windows getting error that npm.ps1 is not digitally signed

Open anonmily opened this issue 1 year ago • 19 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

I upgraded npm using npm install -g [email protected], and then afterwards, I can't use the npm command since I get the code execution error that npm.ps1 is not digitally signed

npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded. The file C:\Program Files\nodejs\npm.ps1 is not digitally signed. You
cannot run this script on the current system. For more information about running scripts and setting execution policy, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.```

### Expected Behavior

It should be able to be run without having to risk the computer's security by allowing unsigned scripts.

### Steps To Reproduce

1. In Windows 11 with Node v20.11.0, upgrade npm from 10.2.4 `npm install -g [email protected]` in Powershell
2. Try to run any npm command (e.g. `npm install`)
3. Get the error that npm.ps1 is not signed


### Environment

- npm: 10.5.0
- Node.js: 20.11.0
- OS Name: Windows 11 Pro
- System Model Name: ?
- npm config: 
```ini
; node bin location = C:\Program Files\nodejs\node.exe
; node version = v20.11.0
; npm local prefix = C:\Users\anonmily\Projects\myapp
; npm version = 10.5.0
; cwd = C:\Users\anonmily\Projects\myapp
; HOME = C:\Users\anonmily
; Run `npm config ls -l` to show all defaults.

anonmily avatar Mar 11 '24 20:03 anonmily

@anonmily running this seems to have fixed it for me in Powershell as an admin. set-ExecutionPolicy RemoteSigned -Scope CurrentUser

dennisrongo avatar Apr 06 '24 19:04 dennisrongo

The issue still persists in 10.5.2. @dennisrongo 's solution works, but I would see it as a temporary workaround.

Do we have any plans on fixing the issue?

ShuzhaoFeng avatar Apr 16 '24 20:04 ShuzhaoFeng

This will need to be coordinated with the Node project. I'm going to keep this issue open to avoid duplicates but any fix for this will need to land in The https://github.com/nodejs/node Windows installer.

lukekarrys avatar May 10 '24 17:05 lukekarrys

@anonmily running this seems to have fixed it for me in Powershell as an admin. set-ExecutionPolicy RemoteSigned -Scope CurrentUser

thank you sir this command resolve my issue.

zakriafurqan1 avatar Jun 26 '24 12:06 zakriafurqan1

I had the problem that I could not run npx commands like npx tailwindcss -i ./tailwind.css -o ./wwwroot/styles.css due to the missing signature and could not run set-ExecutionPolicy RemoteSigned -Scope CurrentUser due to missing admin rights.

This comment solved it for me by using npx.cmd instead of npx: npx.cmd tailwindcss -i ./tailwind.css -o ./wwwroot/styles.css

devbf avatar Jul 23 '24 08:07 devbf

Recently, some similar happend with node -v command

This error ocurrs, from my case and experience, when you update runtime without clean installation. Refering to "clean installation" like remove/uninstall previous node version and deleting all missing/remaining node files like npm-cache, and so on...

I hope to be of help, greatings

Skrigueztep avatar Aug 08 '24 22:08 Skrigueztep

The solution to getting rid of this error message and running your script is simple. But you need to consider the scope before deciding how to fix it:

Do you only want this particular script to run (here and now)? – or Do you want to be able to run all scripts all the time? (these are the two most common options used to solve this problem but more exist!)

If you’re only looking to run the script this one time, use the following command to allow it to run in the current PowerShell session:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process

In the above command, the scope is set to ‘Process’. This means that the new execution policy is only valid in the current process. The old restrictions still apply outside of this specific PowerShell session.

Alternatively, if you want to be able to run scripts freely on your system going forward, use the following command:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

When the scope is set to ‘User’, the new PowerShell execution policy is persisted in the registry and will stick across PowerShell sessions, and system reboots.

Danish0611 avatar Aug 28 '24 09:08 Danish0611

@anonmily running this seems to have fixed it for me in Powershell as an admin. set-ExecutionPolicy RemoteSigned -Scope CurrentUser

thank you

usha2151 avatar Sep 06 '24 05:09 usha2151