Unable to install yarn on windows 10
Asked Answered
J

3

7

I installed node v16.13.0, npm v8.1.0 java version 1.8.0_211 and I thought I also have installed yarn, but trying to install expo using yarn global add expo-cli I get:

yarn : File C:\Program Files\nodejs\yarn.ps1 cannot be loaded. The file C:\Program Files\nodejs\yarn.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.
At line:1 char:1
+ yarn global add expo-cli
+ ~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Then I tried to install yarn again, but now I am 100% unable to get it:

PS C:\Users\user> npm install -g yarn

changed 1 package, and audited 2 packages in 1s

found 0 vulnerabilities

but running yarn --version I get the same error as before:

yarn : File C:\Program Files\nodejs\yarn.ps1 cannot be loaded. The file C:\Program Files\nodejs\yarn.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.
At line:1 char:1
+ yarn --version
+ ~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
Jeremiah answered 24/11, 2021 at 1:39 Comment(2)
Are you running it on powershell? try running it on command promptAdo
By cmd it showed the version that is installed (C:\Users\spike>yarn --version 1.22.15), why can't I get it from powershell? But even using cmd or whatever else, I was unable of using yarn, it was my system environment that had to be changed in the pathJeremiah
F
14

Execute:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Fulmar answered 22/3, 2022 at 19:42 Comment(1)
Wouldn't recommend this approach as the answer by Saber works (and is safer).Favorable
S
6

I suggest not changing your system policy.

Instead, follow this:

Remove yarn.ps1 from the directory C:\Users%username%\AppData\Roaming\npm\ then try clearing the npm cache at C:\Users%username%\AppData\Roaming\npm-cache\

Surfboard answered 8/7, 2022 at 19:35 Comment(5)
I have no npm-cache folderHomesteader
I feel like this is the correct answer. Changing security policies for a single issue is a scary thing, and following these steps corrected the issue for me.Nosey
In my case the file to remove was C:\Program Files\nodejs\yarn.ps1. After removing it (i renamed it), yarn command works.Portsalut
I had nvm so it was in C:\Users\%username%\AppData\Roaming\nvm\v16.20.2\Bald
Why did windows create those ps1 files? I just deleted all of mine. Mine was found at C:\Program Files\nodejs\yarn.ps1Bogie
E
1

Under your npm install directory, rename yarn.ps1 to yarn_disabled.ps1. Now whenever you call yarn, the system will fallback to yarn.CMD which does not have the concept of digital signatures unlike PowerShell.

This is recommended over changing execution policy.

Ethiopia answered 28/8, 2023 at 10:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.