无法在 Windows 10 上安装纱线

6 installation node.js npm-install yarn-workspaces yarn-v2

我安装了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
Run Code Online (Sandbox Code Playgroud)

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

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

changed 1 package, and audited 2 packages in 1s

found 0 vulnerabilities
Run Code Online (Sandbox Code Playgroud)

但运行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
Run Code Online (Sandbox Code Playgroud)

小智 13

执行:

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Run Code Online (Sandbox Code Playgroud)


小智 6

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

相反,请遵循以下步骤:

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

  • 我有 nvm,所以它位于 C:\Users\%username%\AppData\Roaming\nvm\v16.20.2\ (2认同)