If you run into an error with your brand new machine when trying to run any custom scripts like npm, yarn or any node modules you might run into an error similar to below.
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_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1 + yarn + ~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess
To fix it, open PowerShell as administrator, again make sure to run this in PowerShell, not with the regular command prompt (cmd). Copy and paste the code below and run it.
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
This will grant you the necessary permission to run any executable scripts in your PC’s terminal. You only have to do this once and any future yarn or npm commands will run successfully.
Hope this helps with your quick tip on solve why yarn or npm not running on your PC. The same will be true for Ruby’s bundler to manage gems, or Python’s pip package manager.
Was this article Helpful?
Thank you for the feedback!
Lifesaver! The way VS Code handles this has changed, so almost everything else I have read was wrong! Thanks
Thanks so much for sharing!
Thank! this work for me.
It’s worked for me. Thanks!
Thank you dude. This saved my life.
Amazing the yarn docs mention NOTHING about being built on top of PowerShell when on Windows.
Thanks alot !!!
In truth, VS Code has modified its approach
Muito bom. Muito obrigado me ajudou bastante.