yarn : 无法将“yarn”项不能识别为 cmdlet、function( is not recognized报错)

在vscode终端使用yarn install命令下面报错
yarn install
PS F:\ls\quick_redis_blog-2.7.0-alpha> yarn install
yarn : The term 'yarn' is not recognized as the name of a cmdlet, function, script file, or operable program
. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ yarn install
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (yarn:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
在vscode控制台输入(全局安装yarn) :npm install -g yarn
PS F:\ls\quick_redis_blog-2.7.0-alpha> npm install  -g yarn

added 1 package in 7s
npm notice
npm notice New patch version of npm available! 10.2.4 -> 10.2.5
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.2.5
npm notice Run npm install -g [email protected] to update!
npm notice
在执行,报错如下:
PS F:\ls\quick_redis_blog-2.7.0-alpha> yarn install
yarn : File C:\Program Files\nodejs\yarn.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Ptem. For more information, see about_Execution_P
olicies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ yarn install
+ ~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

报错原因:

这是由于 Windows PowerShell 自动阻止不信任的脚本执行造成的,因此需要更改 Windows PowerShell 执行策略。
要更改默认(LocalMachine)作用域的执行策略,请使用“以管理员身份运行”选项启动 Windows PowerShell。
要更改当前用户的执行策略,请运行 “Set-ExecutionPolicy -Scope CurrentUser”。

报错进行修改如下:

查看命令窗口执行的安全策略
PS F:\ls\quick_redis_blog-2.7.0-alpha> get-ExecutionPolicy
Restricted

在这里插入图片描述

设置命令窗口执行的远程策略
set-ExecutionPolicy RemoteSigned 
接着输入确认y

在这里插入图片描述

查看安全策略,已修改成功
 get-ExecutionPolicy

在这里插入图片描述

可以正常使用yarn了

在这里插入图片描述

如果一直显示等待,ctrl+c结束,重新执行yarn install

在这里插入图片描述

修改yarn的镜像源,重新执行yarn install下载快些
yarn config set registry ‘https://registry.npm.taobao.org’

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42786460/article/details/135397319