简体   繁体   English

我在创建 React 应用程序时遇到这样的错误

[英]I'm getting error like this while creating react app

-->
create-react-app : File C:\Users\ADMIN\AppData\Roaming\npm\create-react-app.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
+ create-react-app demo

I think you are using Windows, I came across the same problem and it's because of a security feature in your system.我认为您使用的是 Windows,我遇到了同样的问题,这是因为您的系统中存在安全功能。

  1. Open powershell as an administrator.以管理员身份打开powershell。
  2. Run the following command set-executionpolicy remotesigned运行以下命令set-executionpolicy remotesigned
  3. Try again.再试一次。

This worked for me.这对我有用。

Sources: https://www.faqforge.com/windows/windows-powershell-running-scripts-is-disabled-on-this-system/来源: https : //www.faqforge.com/windows/windows-powershell-running-scripts-is-disabled-on-this-system/

Make sure you remove create-react-app from npm globally and use npx create-react-app {project_name} to generate a react app.确保从npm全局删除create-react-app并使用npx create-react-app {project_name}生成反应应用程序。

npm uninstall --global create-react-app
npx create-react-app sample

also, make sure that your npm version is after 5.2 while doing these.另外,在执行这些操作时,请确保您的 npm 版本在 5.2 之后。

Run power shell as admin以管理员身份运行 power shell

  1. Windows Start Windows 开始
  2. Search for "Windows Powershell"搜索“Windows Powershell”
  3. Right click Windows Powershell右键单击 Windows Powershell
  4. Click Run as Administrator (Grant in "User Account Control" if shows up)单击以管理员身份运行(如果出现,则在“用户帐户控制”中授予)
  5. Type set-executionpolicy remotesigned键入set-executionpolicy remotesigned
  6. Select/Type yes [Y]选择/输入是 [Y]
  • run cmd as adminstrator then然后以管理员身份运行cmd
  • cd to the folder you want to create the app in it and type the following cd 到您要在其中创建应用程序的文件夹并键入以下内容

    create-react-app myapp create-react-app myapp

    this worked for me这对我有用

试试这个命令: npx create-react-app yourappname

只需以管理员身份运行Power shell ,然后执行命令: set-executionpolicy remotesigned

Just stop your node server in "task manager", and start.只需在“任务管理器”中停止您的节点服务器,然后启动。 After that try to install with npx or npm .之后尝试使用npxnpm安装。

Hope it is useful.希望它有用。

Don't worry, I also got this error.别担心,我也遇到了这个错误。 This error comes when you try to write the command create-react-app当您尝试编写命令 create-react-app 时出现此错误

when you type the command npm install -g create-react-app, after running this command you should restart the command prompt or command powershell whatever you are using.当您键入命令 npm install -g create-react-app 时,运行此命令后,您应该重新启动命令提示符或命令 powershell,无论您使用什么。 After restarting command prompt now you can type create-react-app cmd.现在重新启动命令提示符后,您可以键入 create-react-app cmd。

如果您是 Windows 操作系统用户,请打开您的 Powershell 并将以下命令粘贴到您的 PowerShell cmd -> set-executionpolicy remotesigned。

This error comes because Microsoft changed some PowerShell execution policies for your security.出现此错误是因为 Microsoft 为您的安全更改了一些 PowerShell 执行策略。

We can create react app from mainly two places.我们主要可以从两个地方创建 react 应用程序。

  1. Command Prompt - You can easily create new react project without facing any issue.命令提示符- 您可以轻松创建新的 React 项目而不会遇到任何问题。
  2. Powershell terminal in Visual code - If you not disables new policies of powershell yet then you will face such problem.可视化代码中的 Powershell 终端- 如果您还没有禁用 powershell 的新策略,那么您将面临这样的问题。 You need follow some steps to disable these security features.您需要按照一些步骤来禁用这些安全功能。
  • Run power shell as administrator以管理员身份运行 power shell
  • Type set-executionpolicy remotesigned键入set-executionpolicy remotesigned
  • There will be 5 options.会有5个选项。
  • You need to type Y (for [Y] Yes) and click Enter button.您需要输入Y (对于 [Y] 是),然后单击 Enter 按钮。
  • Now you will be able to create react app in your visual code.现在您将能够在您的可视化代码中创建 React 应用程序。

Hope it will work for you.希望它对你有用。

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

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