无法在Windows 10上安装yarn

问题描述 投票:0回答:3

我安装了node v16.13.0,npm v8.1.0 java版本1.8.0_211,我以为我也安装了yarn,但尝试使用yarn global add expo-cli安装expo我得到:

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

然后我再次尝试安装yarn,但现在我100%无法获取它:

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

changed 1 package, and audited 2 packages in 1s

found 0 vulnerabilities

但是运行yarn --version 我得到了与以前相同的错误:

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
node.js installation npm-install yarn-workspaces yarn-v2
3个回答
9
投票

执行:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

3
投票

我建议不要更改您的系统策略。

相反,请遵循以下步骤:

从目录 C:\Users%username%\AppData\Roaming 中删除yarn.ps1 pm\ 然后尝试清除位于 C:\Users%username%\AppData\Roaming 的 npm 缓存 pm-缓存\


0
投票

在 npm 安装目录下,将

yarn.ps1
重命名为
yarn_disabled.ps1
。现在,每当您调用
yarn
时,系统都会回退到
yarn.CMD
,与 PowerShell 不同,它没有数字签名的概念。

建议这样做,而不是更改执行策略。

© www.soinside.com 2019 - 2024. All rights reserved.