简体   繁体   English

将 npm package 安装到 Visual Studio 代码问题时

[英]While installing npm package into visual studio code problem

I have used the command to install npm package into my visual studio code for that, fire a command into my terminal, npm install -g create-react-app but, I am getting errors.我已经使用命令将 npm package 安装到我的 Visual Studio 代码中,为此向我的终端发出命令 npm 安装 -g create-react-app 但是, enter image description here在此处输入图像描述

It's basically saying that Powershell's execution policy does not allow running.ps1 scripts.基本上是说 Powershell 的执行策略不允许 running.ps1 脚本。 When you run npm install, it tries to execute当您运行 npm 安装时,它会尝试执行``

You can solve this in two ways:您可以通过两种方式解决此问题:

  1. Use command prompt instead of Powershell使用命令提示符代替 Powershell
  2. Set script execution policy in Powershell在 Powershell 中设置脚本执行策略

Solution 1解决方案 1

I suggest you take a look at this answer for switching from powershell to command prompt: Visual Studio Code, how to switch from powershell.exe to cmd.exe我建议您查看从 powershell 切换到命令提示符的答案: Visual Studio Code, how to switch from powershell.exe to cmd.exe

Solution 2解决方案 2

Open powershell as administrator, then type the following command in there以管理员身份打开 powershell,然后在其中键入以下命令
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

This will set the execution policy and allow executing remotely signed (third party) scripts, which means NPM can be run.这将设置执行策略并允许执行远程签名(第三方)脚本,这意味着可以运行 NPM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM