繁体   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

我认为您使用的是 Windows,我遇到了同样的问题,这是因为您的系统中存在安全功能。

  1. 以管理员身份打开powershell。
  2. 运行以下命令set-executionpolicy remotesigned
  3. 再试一次。

这对我有用。

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

确保从npm全局删除create-react-app并使用npx create-react-app {project_name}生成反应应用程序。

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

另外,在执行这些操作时,请确保您的 npm 版本在 5.2 之后。

以管理员身份运行 power shell

  1. Windows 开始
  2. 搜索“Windows Powershell”
  3. 右键单击 Windows Powershell
  4. 单击以管理员身份运行(如果出现,则在“用户帐户控制”中授予)
  5. 键入set-executionpolicy remotesigned
  6. 选择/输入是 [Y]
  • 然后以管理员身份运行cmd
  • cd 到您要在其中创建应用程序的文件夹并键入以下内容

    create-react-app myapp

    这对我有用

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

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

只需在“任务管理器”中停止您的节点服务器,然后启动。 之后尝试使用npxnpm安装。

希望它有用。

别担心,我也遇到了这个错误。 当您尝试编写命令 create-react-app 时出现此错误

当您键入命令 npm install -g create-react-app 时,运行此命令后,您应该重新启动命令提示符或命令 powershell,无论您使用什么。 现在重新启动命令提示符后,您可以键入 create-react-app cmd。

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

出现此错误是因为 Microsoft 为您的安全更改了一些 PowerShell 执行策略。

我们主要可以从两个地方创建 react 应用程序。

  1. 命令提示符- 您可以轻松创建新的 React 项目而不会遇到任何问题。
  2. 可视化代码中的 Powershell 终端- 如果您还没有禁用 powershell 的新策略,那么您将面临这样的问题。 您需要按照一些步骤来禁用这些安全功能。
  • 以管理员身份运行 power shell
  • 键入set-executionpolicy remotesigned
  • 会有5个选项。
  • 您需要输入Y (对于 [Y] 是),然后单击 Enter 按钮。
  • 现在您将能够在您的可视化代码中创建 React 应用程序。

希望它对你有用。

暂无
暂无

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

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