yarn: File C:\Users\Administrator\AppData\Roaming\npm\yarn.ps1 cannot be loaded because running scripts is prohibited on this system.

Yesterday I got a new computer. When configuring the environment, I used the VSCode command line to install yarn npm install yarn -G. After the installation was successful, I checked the version and reported an error: yarn: Unable to load file C:\Users\Administrator\AppData\Roaming\npm\ yarn.ps1 because running scripts is prohibited on this system. .

As shown in the figure,
Insert image description here
when I run cmd outside VSCode, I can see that yarn has been installed.
Insert image description here
Then I found the reason: the command line execution policy, the default setting is Restrictednot to load configuration files or run scripts. Need to change the settings to RemoteSigned
How to solve this problem

1. Search powershell, and then run it as an administrator (remember to enter as an administrator)
Insert image description here
2. Enter set-ExecutionPolicy RemoteSigned, press Enter, enter Y after the pop-up content, then close it and
Insert image description here
follow the above two steps. Re-enter VSCode and use yarn.

Guess you like

Origin blog.csdn.net/nihaio25/article/details/126536014