【问题标题】:CLI errror when giving ng serve提供 ng 服务时出现 CLI 错误
【发布时间】:2020-02-29 18:59:27
【问题描述】:
ng : File C:\Users\Lenovo\AppData\Roaming\npm\ng.ps1 cannot be loaded. The file C:\Users\Lenovo\AppData\Roaming\npm\ng.ps1 is not digitally signed. You cannot run 
this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at 
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ ng serve
+ ~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

同时给 ng serve 显示这个错误..如何克服它?

【问题讨论】:

  • Rohan 请尝试在标准 cmd 中使用 ng serve。 Powershell 与标准 cmd 非常不同。
  • 标准cmd表示
  • 按win标志键并输入“cmd”然后回车。 CMD 外壳将打开。那是标准的cmd。 *.ps1 文件运行到 powerShell,这是一个更复杂的 shell,我相信它不受 cli 支持。

标签: angular


【解决方案1】:
  1. 以管理员身份打开 Windows Powershell
  2. 运行以下命令:set-executionpolicy remotesigned
  3. 您现在应该能够在 Visual Studio Code 中运行命令 Angular 和 Node.js 的终端。

Credit

【讨论】:

    【解决方案2】:

    分辨率

    这个问题意味着您的机器正在阻止您运行脚本文件。这些策略的实施发生在 Windows 平台上,包括 Windows 客户端或 Windows Server 机器。 PowerShell执行策略如下:

    格式化和配置文件(.ps1xml), 模块脚本文件 (.psm1),以及 PowerShell 配置文件 (.ps1)。

    解决问题的步骤

    要更改 Windows 计算机上的 PowerShell 执行策略,请使用以下命令:

    第一步: Windows PowerShell 并执行以下命令

    Get-ExecutionPolicy -List
    

    第二步: 一旦你的身份范围和执行策略,请使用相同的运行以下命令。

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
    

    一切就绪,现在输入ng serve,您就可以开始了。快乐编码!

    【讨论】:

      【解决方案3】:

      您需要使用以下命令将 CurrentUser 的 Scope 执行策略设置为 RemoteSigned:

      Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
      

      【讨论】:

        【解决方案4】:

        从同一终端或命令提示符运行以下命令,然后重新运行 ng 命令以检查它是否适用于您的计算机。

        命令是---------Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

        【讨论】:

          【解决方案5】:

          对我来说,这个问题是由全新安装的 VS Code 引起的,它使用 powershell 作为默认终端,而不是 CMD。将默认值更改为 CMD 并从那里执行它为我解决了这个问题。

          【讨论】:

            【解决方案6】:

            您可以尝试将npm start 作为ng serve 的替代品

            对于永久解决方案,您想查看this answer

            【讨论】:

              【解决方案7】:

              在出现错误的同一终端中执行下一个命令:

              Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

              来自 PowerShell 策略链接:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7

              【讨论】:

                【解决方案8】:

                从目录 C:\Users\\AppData\Roaming\npm\ 中删除 ng.ps1,然后尝试清除 C:\Users\\AppData\Roaming\npm-cache\

                对我来说这很有效,只是遇到了同样的问题。

                此修复的作者来自THIS 帖子。

                【讨论】:

                • 还做了 npm update 和 npm audit fix,但你可能不需要,我只是做了,因为我认为我需要它。
                猜你喜欢
                • 2019-01-01
                • 1970-01-01
                • 2021-02-07
                • 2020-05-30
                • 2014-04-12
                • 2016-11-08
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多