Search code examples
javascriptwindowsyarnpkg

Yarn commands can't be executed in the regular way


When a yarn command is getting executed, it gives an security error as an unauthorized access.

yarn : File %FILEPATH%\yarn.ps1 cannot be loaded because running scripts is disabled on this        
system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ yarn start
+ ~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

But it can be by bypassed using the command shown below.

powershell -ExecutionPolicy Bypass -File '%FILEPATH%\yarn.ps1' yarn start

All the npm commands are working fine and the errors only occurred when executing the yarn commands. And the commands were run on windows 10 operating system.
Is there way to execute the yarn commands in regular way? ( just executing only the command as yarn start)


Solution

  • It seems a bug in PowerShell

    Have you installed node on your system?

    try to uninstall yarn

    and try to install it with the installer

    This will give you a .msi file that when run will walk you through installing Yarn on Windows.

    If you use the installer you will first need to install Node.js.

    If it does not work, you can use a command described in this link link

    Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

    also this link could help you